Link to home
Start Free TrialLog in
Avatar of jtcy
jtcy

asked on

PHP: Object oriented question

I have a class:

class student(
public $name;

public function __construct(){
$name = "yes";
}

public function getName(){
echo($name);
}

}

Why is that the name in getName() doesnt get the updated name? How to solve this?
ASKER CERTIFIED SOLUTION
Avatar of rhysp
rhysp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rhysp
rhysp

Actually, more completely:

class student {
   public $name;

   public function __construct(){
      $this->name = "yes";
   }

   public function getName(){
      echo($this->name);
   }
}

For details of classes in PHP, http://www.php.net/manual/en/language.oop5.php