On 05.10.2016 at 16:40, Michael Cinicola wrote:

> The last line in the example:
> 
> 
> 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; // Works
> echo $obj->protected; // Fatal Error
> echo $obj->private; // Fatal Error
> $obj->printHello(); // Shows Public, Protected and Private
> 
> 
> does not show public, protected, and private:
> 
> Tried on Chrome and Safari on macOS Sierra — no result on either.
> 
> Source: http://php.net/manual/en/language.oop5.visibility.php 
> <http://php.net/manual/en/language.oop5.visibility.php>

This example is not supposed to work verbatim; of course, you have to
remove the lines that throw a fatal error which terminates the script.
See <https://3v4l.org/U6HtI>.

-- 
Christoph M. Becker

-- 
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to