ID: 18024 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Feedback +Status: No Feedback Bug Type: Scripting Engine problem Operating System: Windows XP home PHP Version: 4.2.0 New Comment:
No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you. Previous Comments: ------------------------------------------------------------------------ [2002-09-05 16:12:44] [EMAIL PROTECTED] First, PHP is not an OOP language, it is a scripting language that supports OOP-style coding. Second, as the type of variables or their existence is dynamic (i.e. no need to declare a variable or its type before using it), and as there is no concept of private/public/protected/etc. then it is the expected behaviour that the subclass overrides the parent's if you use it directly, similar behaviour happens if you override a parent's method. Third, there are no namespaces as such in PHP (need I elaborate more?) BTW, you can still refer to the parent's members using the parent keyword, e.g. parent::foo(), in other words you should refer to the var/method explicitely in the code. If you have some code contribution that can implement the behaviour you are used in C++ or other OOP language, feel free to submit it to the php-dev list. It will be good if you look at the archives and read the discussions on the OOP topics that have happened before there too. ------------------------------------------------------------------------ [2002-09-04 03:38:49] [EMAIL PROTECTED] I have the same problem and i'm using php 4.0.6 on linux ------------------------------------------------------------------------ [2002-06-27 16:26:56] [EMAIL PROTECTED] I am surprised that a subclass can redeclare parent class variables. It seems to me that this could hinder reusability, as a programmer must know all variables declared in the parent class (possibly coded by another programmer) to avoid mistakes. Consider the following code: ---code--- class Father { var $variable = "father"; function parentVar() {return $this->variable;} } class Child extends Father { var $variable = "child"; function childVar() {return $this->variable;} } $testChild = new Child(); echo "Expect child : ". $testChild->childVar() . "\n"; echo "Expect father : ". $testChild->parentVar() . "\n"; ---endcode--- In java or C++, Father::variable and Child::variable would be different variables; References to $this->variable would refer to Child::variable in Child and to Father::variable in Father. The redefinition would not break any functions written in Father. Member functions in Child could access Father::variable by specifying it. The PHP documentation hints that this was considered. Indeed, in the documentation for :: one can read "Sometimes it is useful to refer to functions and variables in base classes or to refer to functions in classes that have not yet any instances. The :: operator is being used for this." However, the actual behaviour is PHP is that the Child class overwrites the variable from the Father, as can be seen by running the script. The results are : Expect child : child Expect father : child Am I overseeing something ? Thanks for your attention, Alain Dresse ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18024&edit=1