For example, the following code, the result of printing only shows the public, and then reported a fatal error, then the occupation skip the mistake to let the next program continue to execute it? The desired output format is
Public
Error
Error
Public protected private
Class MyCLass
{
Public $public = ' public ';
Protected $protected = ' protected ';
Private $private = ' private ';
function Printhello ()
{
Echo $this->public;
Echo $this->protected;
Echo $this->private;
}
};
$obj =new MyCLass ();
Echo $obj->public;
Echo $obj->protected;
Echo $obj->private;
$obj->printhello ();
Reply to discussion (solution)
Try catch capture processing under
Is that so? But the second line of error, the code behind will not be executed AH
try {
Echo $obj->protected;
} catch (Emptyiterator $e) {
Print $e->getmessage ();
}
Cannot access protected property MyCLass:: $protected
Unable to access protected resource
This is a fatal error, not to be avoided!
In other words: You don't know the rules.
You can use simple debugging functions to observe the properties of an object
Print_r ($obj);
Or
Var_dump ($obj);
A fatal error is no way to skip, and once it happens, it stops running.
Thanks, everybody.