implicit public peroperties

php.internals

(Marcus Börger)

23 years ago
Hello internals, The following code: <?php class a { protected $bla; } class b extends a { public function murks() { return $this->bla; } } $o = new b; print_r($o) ?> results in two properties which is wrong: b Object ( [bla] => [bla:protected] => ) I tried to fix this bug and found three solutions: 1) when the new class does its inheritance checks it could 'merge' the two properties (remove the implicit public one). But this approach is very small and imho the wrong way. 2) implicit public properties are declared at compile time by the function zend_do_declare_implicit_property(). This function has access to the class entry of the class to be declared. However that class is not initialized yet and doesn't know about it's parent class entry. So i suggest we make this code new opcode. Since then we would do it at run time the class entry can already know its parent and the property lookup can finally find inherited members. 3) Don't have implicit public declared properties at all. That would be a more purist approach which only allows properties declared in the class and dynamic object properties that are not part of the class. Unluckily the problem also happens when you declare the property in the derived class as public, too. So i think we really need a new opcode. Any thoughts?
-- Best regards, Marcus mailto:helly@php.net

Zeev Suraski

23 years ago
Fixed! At 01:17 28/08/2003, Marcus Börger wrote:

(Marcus Börger)

22 years ago
Hello Zeev, Friday, August 29, 2003, 10:15:57 AM, you wrote:
> Fixed!
Yes you fixed it for implicit properties and i fixed it for internal properties. Now we still have to fix it for user space default properties and static properties. And for static properties we should disallow overriding the initial value becasue that make no sense at all.
-- Best regards, Marcus mailto:helly@php.net

Brad Bulger

22 years ago
I hope that these fixes don't mean that the following is now on-purpose behavior: <?php class base { public $x = 1; } class bar extends base { public function __construct() { var_dump($this->x); } } $b = new bar; ?> Output: Notice: Undefined property: bar::$x in ack.php on line 10 NULL On Wed, 3 Sep 2003, Marcus Börger wrote:

(Marcus Börger)

22 years ago
Hello Brad, funny i checked so many complex errors that i overlooked one of the more obvious errors. In your script an implicit public property would overwrite an inherited public one. During class inheritance the default value must now be copied from parent to child. The copy code however also works for situations other situations, for instance when the inherited property is proteced. And there the order of destructing the old default value and copying the new one didn't matter. In this case it does - oder fixed now. Monday, September 8, 2003, 10:24:49 PM, you wrote:
> I hope that these fixes don't mean that the following is now > on-purpose behavior:
> <?php > class base > { > public $x = 1; > } > class bar extends base > { > public function __construct() > { > var_dump($this->x); > } > } > $b = new bar;
?>>
> Output: > Notice: Undefined property: bar::$x in ack.php on line 10 > NULL
> On Wed, 3 Sep 2003, Marcus Börger wrote:
>> Hello Zeev, >> >> Friday, August 29, 2003, 10:15:57 AM, you wrote: >> >> > Fixed! >> >> Yes you fixed it for implicit properties and i fixed it for internal >> properties. Now we still have to fix it for user space default properties >> and static properties. And for static properties we should disallow >> overriding the initial value becasue that make no sense at all. >> >> >> -- >> Best regards, >> Marcus mailto:helly@php.net >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >>
-- Best regards, Marcus mailto:helly@php.net