Re: Public, Protected, and Private -- Not working

From: Date: Wed, 05 Oct 2016 14:57:47 +0000
Subject: Re: Public, Protected, and Private -- Not working
References: 1  Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-25225@lists.php.net to get a copy of this message
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

« previous php.webmaster (#25225) next »