Re: LSB forward_static_call()

From: Date: Mon, 23 Jun 2008 17:22:42 +0000
Subject: Re: LSB forward_static_call()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-38551@lists.php.net to get a copy of this message
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.
"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. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

« previous php.internals (#38551) next »