Re: [PHP4BETA] OOP issue

From: Date: Wed, 17 Nov 1999 05:00:13 +0000
Subject: Re: [PHP4BETA] OOP issue
References: 1 2  Groups: php.version4 
Request: Send a blank email to php-version4+get-6342@lists.php.net to get a copy of this message
At 08:52 PM 11/16/99 +0200, Teodor Cimpoesu wrote:
Kristian Köhntopp wrote: Andi Gutmans wrote:
In PHP 4 if the child doesn't define a constructor it's supposed to inherit the parents constructor. Only if you override the constructor do you need to call the parent constructor explicitly.
Did I understand this correctly: When I define a class Y extends X without providing Y::y() and X::x() is a constructor in X, a $y = new Y does call Y::x()? Ok, that works and it is probably the most confusing way to implement it. I think it sounds more like `real' OO behaviour, though I would expect Y::x() to be called even Y::y() exists. Also the support for `var $v' declarations breaks some things like in class A { function A() { $this->a = 1; } }; class B extends A { var $a = 2; function foo(){echo $this->a;} }; $z = new B; echo $z->foo(); This won't output 2 as expected but 1.
I don't quite agree. It should output 1. Your constructor changes it. If you don't want the constructor to be called then override it with a constructor for B. Andi --- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.version4 (#6342) next »