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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php