Re: Fwd: Re: [PHP] Private and protected variables in PHP 5?

From: Date: Sat, 12 Jul 2003 16:10:10 +0000
Subject: Re: Fwd: Re: [PHP] Private and protected variables in PHP 5?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-3387@lists.php.net to get a copy of this message
Alan, > I think what you are getting at is that you can set 'private' variable > from outside.. - with no warnings etc. Yup. > so if you want a warning when you set/create a variable with the same > name as the private - use protected... > Or am I missing the point on what you expected..? I was expecting setting a private variable to error out. Protected works as you say - it errors out as expected. But surely private should error also - inherited classes inherit private variables, but they can't manipulate them (or at least so I thought). This code: <?php class dog { private $Name; protected function bark() { print "Woof!\n"; } } class poodle extends dog { // nothing happening here } $mydog = new poodle; $mydog->Name = "Poppy"; var_dump($mydog); ?> Outputs this: object(poodle)#1 (2) { [""]=> NULL ["Name"]=> string(5) "Poppy" } I'm not sure what the [""]=>NULL is, but it isn't there if I shift $Name into the poodle class and make it public. --Paul

« previous php.internals (#3387) next »