<?php
/**
* Created by PhpStorm.
* User: dell
* Date: 2019/10/4
* Time: 21:20
*/
class MyClass{
public function __construct()
{
echo "__construct";
}
public function MyPublic(){
echo "MyPublic";
}
protected function MyProtected(){
echo "MyProtected";
}
private function MyPrivate(){
echo "MyPrivate";
}
function Foo(){
$this->MyPublic();
$this->MyProtected();
$this->MyPrivate();
}
}
$myclass = new MyClass();
$myclass->MyPublic(); //这行能正常执行
$myclass->MyProtected(); //这里会发生致命错误
$myclass->MyPrivate(); //同上
$myclass->Foo();
class MyClass2 extends MyClass{
function Foo2(){
$this->MyPublic();
$this->Myprotected();
$this->MyPrivate(); //这行会产生一个致命错误
}
}
$myclass2 = new MyClass2();
$myclass2->MyPublic(); //这行能被正常执行
$myclass2->Foo2(); //公有和保护的都可以执行,私有的不可执行