Re: LSB forward_static_call()

From: Date: Tue, 24 Jun 2008 05:07:37 +0000
Subject: Re: LSB forward_static_call()
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-38561@lists.php.net to get a copy of this message
On 6/23/08, Stanislav Malyshev <stas@zend.com> wrote: > Hi! > > > > why would anyone need that? > > > > To use function that does use static without dependence on in which context > if was called (or, explaining it other way, when your chain of inheritance > serves multiple purposes): > > class ActiveRecord { > static function getRow($condition) { > $table = new Table(get_called_class()); > return $table->find($condition); > } > } > > class Users extends ActiveRecord { > } > > class DepartmentUsers extends Users { > static function find($user) { > if(self::user_in_department($user)) { > return parent::getRow("user=$user"); > } > return false; > } > } > > $user = DepartmentUsers::find("bob"); > > Now in this case if your way is implemented, ActiveRecord would try to find > table for DepartmentUsers, which probably does not exist. You would have to > name Users by name there to do what this code wants to do, which leads us > back to "why we have parent:: at all" argument. in my ActiveRecord, table for DepartmentUsers would actually exist ;) > > "parent" is related to inheritance and it is logical, that it retains > > call-chain. > > > > It is "logical" if you look at it with the narrow point of view of what you > need for your particular application. However, there are other use cases. > Automatic forwarding may become very awkward if you have multiple levels of > inheritance not all of them used for the same thing. I am just looking for consistency. I am expecting get_called_class() to work as a static analog of get_class(this) -- Alexey Zakhlestin http://blog.milkfarmsoft.com/

« previous php.internals (#38561) next »