note 36563 added to keyword.parent

From: Date: Wed, 15 Oct 2003 02:31:13 +0000
Subject: note 36563 added to keyword.parent
Groups: php.notes 
Request: Send a blank email to php-notes+get-58600@lists.php.net to get a copy of this message
based on a note from horne earlier: I find the whole OOP and inherited variable scheme quite confusing. What is the point of declaring a variable in a base class? The following code requires that the same variables get declared for each extended class. Doesn't this fly in the face of code reuse? For the following code to work, you would need to know the name of the variable that the inherited disp() function uses, and then set it in the calling class, rendering the power of extended classes much weaker. (example from Calimero) <? class A { var $name='A'; function disp() { echo $this->name; } } class B extends A { var $name='B'; } class C extends B { var $name='C'; } $truc = new C() ; $truc->disp(); // Will output C ?> Also, what is the point of even declaring a class variable if it isn't a constant across all classes? Simply setting a variable on the fly, using <? $this->myvar = "foo"; ?> works regardless of whether it was declared or not. I shudder at the thought of debugging a class that is only slightly more complicated. It seems more straighforward to simply adopt a functional approach to PHP, over the OOP variety. It seems difficult to keep track of the variables used in the inherited methods. Someone please post something telling me I'm wrong. ---- Manual Page -- http://www.php.net/manual/en/keyword.parent.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36563 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36563&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36563&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58600) next »