当前位置:网站首页>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 notes] 08 enumeration and mode
- 单调栈-84. 柱状图中最大的矩形
- Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)
- Image processing 8-cnn image classification
- Redux - learning notes
- XPath实现XML文档的查询
- Alibaba canal actual combat
- [rust notes] 09- special types and generics
- [public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
- UE4 source code reading_ Mobile synchronization
猜你喜欢

22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制

Analysis of Alibaba canal principle

单调栈-42. 接雨水

Es8 async and await learning notes

Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation

Unity editor expansion - scrolling list

Unity interactive water ripple post-treatment
![[redis] redis persistent RDB vs AOF (source code)](/img/57/b6a86c49cedee31fc00dc5d1372023.jpg)
[redis] redis persistent RDB vs AOF (source code)

MySQL 8

Concurrent programming (VI) ABA problems and solutions under CAS
随机推荐
Monotonic stack -84 The largest rectangle in the histogram
Sequence of map implementation classes
How to place the parameters of the controller in the view after encountering the input textarea tag in the TP framework
PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
[rust notes] 08 enumeration and mode
Final review of Database Principles
Osgearth target selection
Notes on understanding applets 2022/7/3
SQL statement error of common bug caused by Excel cell content that is not paid attention to for a long time
P1596 [USACO10OCT]Lake Counting S
Cesium for unreal quick start - simple scenario configuration
Location of package cache downloaded by unity packagemanager
Dealing with duplicate data in Excel with xlwings
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
Redux - learning notes
Allocation exception Servlet
Dom4j traverses and updates XML
796 · unlock
Dom4j遍历和更新XML
Animation_ IK overview