Pierre-Alain Joye wrote:
On Wed, 18 Feb 2004 12:23:04 -0500 John Coggeshall <[EMAIL PROTECTED]> wrote:
class foo { static function bar() { } } $a = new foo(); $a->bar(); /* Unacceptable and contradictory to the concept of static */ foo::bar(); /* Acceptable */
I have the same problem as George :) I did not understand well your original post.
We are talking about the same thing. A notice (error sounds too drastic here) should be raised if a static method is called from the instanciated object.
I disagree w/ any sort of error being raised by calling a static method from object context. I think it should be allowed because
1) there is already the stuff in static to disallow any reference to $this, so there is no danger of a static method messing w/ instance variables. (i.e. if you're calling it by accident, you'll probably find out pretty quickly)
2) In some cases it is useful to instantiate an otherwise static class for the sake of passing it to some code that doesn't know the name of the static class.
For example in Propel (PHP5 Torque port) the "Peer" classes are static classes that do work on entities -- like inserting them in the database, etc. If I have an array of Entity objects, I might want to get access to the Peer class that handles those entities, so I have:
foreach($entities as $ent) { $peer = $ent->getPeer(); // e.g. might be BookPeer $peer->doSelect(new Criteria()); //static: BookPeer::doSelect() }
This [taken from Java Torque impl] is particularly useful because the alternative is having to invoke the method using call_user_func() or eval() (yuk!).
Hans
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php