View Single Post
Old 11-17-2008, 03:44 PM   #11 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

php Code:
class Welcome
    {
       
        private $newUser;
        private $myName;
       
        public function __construct($name)
        {
           
            if(is_string($name))
            {
               
                $this->newUser = $name;
               
            }
           
            else throw new Exception('Parameter only supports string.');
           
        }
       
        public function setName($name)
        {
           
            if(is_string($name))
            {
               
                $this->myName = $name;
               
            }
           
            else throw new Exception('Parameter only supports string.');
           
        }
       
        public function getWelcome()
        {
           
            $string = 'Welcome dear ' . $this->newUser . ' to TalkPHP. Hope you enjoy the site!<br />Kind regards, ' . $this->myName;
           
            return $string;
           
        }
       
    }

PHP Code:
$msg = new Welcome('Dal');
$msg->setName('Tanax');
    
echo 
$msg->getWelcome(); 
Code:
Welcome dear Dal to TalkPHP. Hope you enjoy the site!
Kind regards, Tanax
__________________
Tanax is offline  
Reply With Quote