Copy code The code is as follows:
class Foo
{
private $name = 'hdj';
public function getName(){
return $this->name;
}
}
class Bar extends Foo
{
public $name = 'deeka';
}
$bar = new Bar;
var_dump($bar->name);
var_dump($bar->getName());
Access control
Access control on properties or methods is achieved by adding the keywords public, protected or private in front. Class members defined by public can be accessed from anywhere; class members defined by protected can be accessed by subclasses and parent classes of the class in which they are located (of course, the class in which the member is located can also be accessed); and by private The defined class members can only be accessed by the class in which they are located.
http://www.bkjia.com/PHPjc/326011.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326011.htmlTechArticleCopy the code The code is as follows: class Foo { private $name = 'hdj'; public function getName(){ return $ this-name; } } class Bar extends Foo { public $name = 'deeka'; } $bar = new Bar; va...