公共函数调用没有在私有变量的代码之后执行


The public function call is not getting executed after the code of private variable

<?php
/* example for access specifiers*/
class myClass
{
    var $car = "alto"; //if we declare as var it is automatically considered as public
    public $pub = "alphanso"; //even no need to using public keyword  as it is public bydefault
    private $pri = "zen";
    public function myPublic()
    {
        echo "I'm public...can be accessible everywhere";
    }
    private function myPrivate()
    {
        echo "I'm private...no where am accessible,except in current class";
    }
}
$accss = new myClass;
echo $accss->car . "<br>";
echo $accss->pub . "<br>";
echo $accss->pri . "<br>";
$accss->myPublic();
$accss->myPrivate(); //visible only in the class where it is declared.

?>

您不能访问private成员或类外的方法,尝试这样做将引发FATAL错误。

它不能访问$accss -> myPublic();,因为你在这里遇到一个致命错误,echo $accss -> pri."<br>";按照上面我指定的条件。

所以其余的代码将不执行