Re: Class::__construct() vs. $this->__construct()

From: Date: Wed, 30 Mar 2005 22:18:15 +0000
Subject: Re: Class::__construct() vs. $this->__construct()
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-37002@lists.php.net to get a copy of this message
On Wed, 30 Mar 2005 14:07:39 -0800, Ian Eure <ieure@php.net> wrote: > On Wednesday 30 March 2005 01:50 pm, Joe Stump wrote: > > Thoughts? > > > From a PHP4 constructor, it needs to be $this->__construct(), otherwise > __construct() runs outside the context of the newly instantiated object (i.e. > there's no $this to initialize). > > I'm not sure about the parent::__construct() use. Does anyone know if this a > special case which allows use of $this, unlike other static calls? > In C++ this would be the case, but if you run a function with :: $this is still available. Check out this code (which is even more disturbing): class A { var $a = 'a'; function output() { echo $this->a; } } class B { var $a = 'b'; function output() { A::output(); } } $b = new B(); $b->output(); There is really no "static" context in PHP4. (I'm not sure about PHP5) -- Justin Patrin

« previous php.pear.dev (#37002) next »