当前位置:网站首页>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()
?>
边栏推荐
- 【Rust 笔记】09-特型与泛型
- [concurrent programming] thread foundation and sharing between threads
- Data analysis exercises
- Concurrent programming (VI) ABA problems and solutions under CAS
- Concurrent programming (III) detailed explanation of synchronized keyword
- [redis] redis persistent RDB vs AOF (source code)
- Alibaba canaladmin deployment and canal cluster Ha Construction
- Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
- Alibaba canal actual combat
- XPath实现XML文档的查询
猜你喜欢

22-06-27 Xian redis (01) commands for installing five common data types: redis and redis

Animation_ IK overview

Chocolate installation

Kunlunbase meetup is waiting for you!

OpenGL learning notes
![[updating] wechat applet learning notes_ three](/img/05/958b8d62d3a42b38ca1a2d8631a7f8.png)
[updating] wechat applet learning notes_ three

Final review of Database Principles

Concurrent programming (VI) ABA problems and solutions under CAS

Unity interactive water ripple post-treatment

请求参数的发送和接收
随机推荐
Final review of Database Principles
Notes on understanding applets 2022/7/3
Unity Editor Extension - drag and drop
Analysis of Alibaba canal principle
第一个Servlet
Deeply understand the underlying data structure of MySQL index
Osgearth starry background
file_ put_ contents
MySQL index types B-tree and hash
MySQL containerization (1) docker installation MySQL
[audio and video] ijkplayer error code
Allocation exception Servlet
VIM learning notes from introduction to silk skating
On the difference and connection between find and select in TP5 framework
Dom4j遍历和更新XML
JS ternary operator - learning notes (with cases)
Graphics_ Learnopongl learning notes
Unity editor expansion - the framework and context of unity imgui
Alibaba canal actual combat
【Rust笔记】06-包和模块