当前位置:网站首页>php public private protected
php public private protected
2022-07-03 08:48:00 【bin9153】
public Global representation , Class internal and external subclasses can access ;
private For private , Only this class can be used internally ;
protected Indicates protected , Only this class or subclass or parent class can access ;
<?
// Parent class
class father{
public function a(){
echo "function a";
}
private function b(){
echo "function b";
}
protected function c(){
echo "function c";
}
}
// Subclass
class child extends father{
function d(){
parent::a();// Calling the a Method
}
function e(){
parent::c(); // Calling the c Method
}
function f(){
parent::b(); // Calling the b Method
}
}
$father=new father();
$father->a();
$father->b(); // Display error External cannot call private method Call to protected method father::b()
$father->c(); // Display error Protected methods cannot be called externally Call to private method father::c()
$chlid=new child();
$chlid->d();
$chlid->e();
$chlid->f();// Display error Cannot call parent class private Methods Call to private method father::b()
?>
边栏推荐
- Life cycle of Servlet
- Image processing 8-cnn image classification
- [concurrent programming] working mechanism and type of thread pool
- MySQL index types B-tree and hash
- MySQL 8
- PHP function date (), y-m-d h:i:s in English case
- Kunlunbase meetup is waiting for you!
- [set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
- 22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
- Alibaba canal actual combat
猜你喜欢
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
ES6 promise learning notes
Monotonic stack -503 Next bigger Element II
How to place the parameters of the controller in the view after encountering the input textarea tag in the TP framework
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
Alibaba canal actual combat
[cloud native] introduction and use of feign of microservices
【Rust笔记】02-所有权
Dom4j traverses and updates XML
Installation of PHP FPM software +openresty cache construction
随机推荐
[updating] wechat applet learning notes_ three
Deep parsing JVM memory model
Talking about: is the HashSet set ordered or disordered /hashset set unique, why can we store elements with the same content
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
[rust notes] 12 closure
Monotonic stack -84 The largest rectangle in the histogram
Monotonic stack -42 Connect rainwater
producer consumer problem
【Rust 笔记】07-结构体
【Rust 笔记】10-操作符重载
【Rust 笔记】13-迭代器(上)
PHP function date (), y-m-d h:i:s in English case
Servlet的生命周期
Animation_ IK overview
Concurrent programming (III) detailed explanation of synchronized keyword
MySQL containerization (1) docker installation MySQL
分配异常的servlet
Unity Editor Extension - drag and drop
Unity editor expansion - the framework and context of unity imgui
Swagger document configuration