note 36563 deleted from keyword.parent by vincent
| From: | vincent@php.net | Date: | Wed, 15 Oct 2003 07:52:33 +0000 |
| Subject: | note 36563 deleted from keyword.parent by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58608@lists.php.net to get a copy of this message | ||
Note Submitter: gdbj@have.a.nice.day.com
----
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.