{{PHP}}PHP inherited access control_PHP tutorial

WBOY
Release: 2016-07-13 17:53:10
Original
1099 people have browsed it

{{PHP}}PHP inherited access control

When talking about inheritance, you have to mention access control. Inheritance behaves differently under different access control permissions. Taking member methods as an example, we can use private and protected access modifiers to control what needs to be inherited.

private If a member is designated as private, it cannot be inherited. In fact, this method will be inherited in PHP, but it will not be accessible.
protected If a member is designated as protected, it will not be visible outside the class and can be inherited.

Look at an example in PHP:

class Base {
private function privateMethod() {
}
}

class Child extends Base{
Public function publicMethod() {
}
}

$c = new Child();

if (method_exists($c, 'privateMethod')) {
echo 1;
}else{
echo 0;
}


Author: bill200711022

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478062.htmlTechArticle{{PHP}}PHP Inherited Access Control When talking about inheritance, you have to mention access control. Inheritance behaves differently under different access control permissions. Taking member methods as an example, we can use...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template