Example Analysis of PHP access Control
This article mainly introduces the example analysis of PHP access control, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.
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 to a property or method is achieved by adding the keyword public, protected, or private. A class member defined by public can be accessed anywhere; a class member defined by protected can be accessed by a subclass and parent of its class (of course, the class in which it belongs can also be accessed); and a class member defined by private can only be accessed by its own class.
Thank you for reading this article carefully. I hope the article "sample Analysis of PHP access Control" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!