• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

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?
0
jtcy
Asked:
jtcy
  • 2
1 Solution
 
rhyspCommented:
public function getName(){
echo($this->name);
}
0
 
rhyspCommented:
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
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now