ID: 38037 Updated by: [EMAIL PROTECTED] Reported By: panza at zs dot lviv dot ua Status: Wont fix Bug Type: Class/Object related -Operating System: FreeBSD +Operating System: * -PHP Version: 5.1.4 +PHP Version: 5.* New Comment:
Not in 5.2 Previous Comments: ------------------------------------------------------------------------ [2006-07-07 22:01:03] panza at zs dot lviv dot ua Just to clarify... How long untill we see this feature in action? PHP 5.1.5, PHP 5.2 or PHP. Just wondering about the timeframe, since I don't think there's any work arounds without changing the Base class? ------------------------------------------------------------------------ [2006-07-07 21:50:08] [EMAIL PROTECTED] Yes. methods defined in class A are executed in context of class A. We're working on late static binding, but currently it's not available in PHP, you have to wait until it's ready. ------------------------------------------------------------------------ [2006-07-07 21:46:37] panza at zs dot lviv dot ua Description: ------------ I have searched Bugs throughout, and found similar problems, addressing the visibility issue, this is quite different... During inheritance, the private members of the parent class are inheriated as well, but can only be modified by the methods defined in parent class. The methods defined in the child class can not modify these variables, but only child's own members. The problem here is, that theoretically this situation seems wrong. Once inherited, the methods should "belong" to the child, therefore even though they are defined in parent, they should modify child's members when called, No? Also in this situation, as shown in the code during var_dump of the $b variable, we can see two private "_vars" members, how can this be logical, two variables with same name belong to same namespace,yet one only accessible by it's parents methods,while other by it's own methods. Note: I first came across this problem, while using Zend Framework and extending Zend_View class. If needed I can send source to show the importance of this. In my opinion, the "old" parents private members should not be shown using var_dump and similar output functions to stop confussion, and the inherited methods should work with members in the child class, not parent, since they were called from child class and the logic would suguest this. Reproduce code: --------------- http://www.zs.lviv.ua/~panza/error.phps Expected result: ---------------- $this belongs to B $this belongs to B Variable, $b->somevar, was assigned in B costructor, but the call was made to __set in parent class, A, making it defined in _vars which belongs to A. During retrive, we __get from parent is called, so we get the value we assigned string(6) "value1" Although, this time retriving the same variable using function defined in child class, B, we get NULL. string(6) "value1" This is because when inheriting a class, the private variables are inherited as well, but only access by function which were defined in the parent class. The functions that were defined in child class modify/access their own variable with the same name. object(B)#1 (3) { ["_glovalvars:private"]=> NULL ["_vars:private"]=> array(3) { ["somevar"]=> string(6) "value1" ["UsingfunctionFromA"]=> string(14) "Set _vars in A" ["UsingB"]=> string(15) "Sets _vars in B" } } Actual result: -------------- $this belongs to B $this belongs to B Variable, $b->somevar, was assigned in B costructor, but the call was made to __set in parent class, A, making it defined in _vars which belongs to A. During retrive, we __get from parent is called, so we get the value we assigned string(6) "value1" Although, this time retriving the same variable using function defined in child class, B, we get NULL. NULL This is because when inheriting a class, the private variables are inherited as well, but only access by function which were defined in the parent class. The functions that were defined in child class modify/access their own variable with the same name. object(B)#1 (3) { ["_glovalvars:private"]=> NULL ["_vars:private"]=> array(1) { ["UsingB"]=> string(15) "Sets _vars in B" } ["_vars:private"]=> array(2) { ["somevar"]=> string(6) "value1" ["UsingfunctionFromA"]=> string(14) "Set _vars in A" } } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38037&edit=1
