class inheritance

php.internals

Thomas Moenicke

20 years ago
Hi, I have two classes, A and B: B inherits from A. B is written in PHP, A is implemented inside of an extension. B has an array: class B extends A { var $myArray = array("one", "two", "three"); function __construct() { parent::__construct(); } } Is it possible to access $myArray in the parents constructor? Therefor I need the zval* pointer of the child! I do not want to pass it as an argument. Thanks and regards, Thomas

Marcus Börger

20 years ago
Hello Thomas, sure php is unlike c++ where everything is handled via vmt's that change during construction. In php the ctors are called after the default values are applied to every member variable. Actually the most outer ctor is being called so in your case B's. If that is calling into A's ctor which is in your case a c implementation you can easily access that member just as any other. best regards marcus Tuesday, May 9, 2006, 1:32:10 AM, you wrote:
> Hi,
> I have two classes, A and B: B inherits from A. B is written in PHP, A is > implemented inside of an extension. B has an array:
> class B extends A > { > var $myArray = array("one", "two", "three");
> function __construct() > { > parent::__construct(); > }
> }
> Is it possible to access $myArray in the parents constructor? Therefor I need > the zval* pointer of the child!
> I do not want to pass it as an argument.
> Thanks and regards, > Thomas
Best regards, Marcus

Thomas Moenicke

20 years ago
Hi Marcus, Marcus Boerger wrote:
> sure php is unlike c++ where everything is handled via vmt's that change > during construction. In php the ctors are called after the default values > are applied to every member variable. Actually the most outer ctor is being > called so in your case B's. If that is calling into A's ctor which is in > your case a c implementation you can easily access that member just as any > other.
Thanks for pointing that out. I got segfaults while trying to access the arrays, but the problem was an uninitialized array. The zval->type == IS_ARRAY statement can protect the access. regards, Thomas