I think __invokeStatic() would be a very useful magic function, especially
with support for late static binding.
you could difine it one and all sub-classes will have that option of
basically being callable classes.
MyClass($params) could then do some processing and return some data.
This would basically be the same as doing MyClass::doSomething($params);
only without the extra typing of ::doSomething
Dmitri Snytkine
Web Developer
Ultra Logistics, Inc.
Phone: (888) 220-4640 x 2097
Fax: (888) 795-6642
E-Mail: dsnytkine@ultralogistics.com
Web: www.ultralogistics.com
"A Top 100 Logistics I.T. Provider in 2011"
How would this be different from defining a function MyClass?
Nikita
On Mon, Nov 28, 2011 at 9:02 PM, Dmitri Snytkine
dsnytkine@ultralogistics.com wrote:
I think __invokeStatic() would be a very useful magic function, especially
with support for late static binding.
you could difine it one and all sub-classes will have that option of
basically being callable classes.MyClass($params) could then do some processing and return some data.
This would basically be the same as doing MyClass::doSomething($params);
only without the extra typing of ::doSomething
How would this be different from defining a function MyClass?
Actually, I just found myself wanting this the other day. The class
name in question was being defined in a config file, which the user
would be free to override with their own class name (and a closure was
ruled out because this config file could be xml/ini/etc). There are
plenty of other ways I decided I could work around this, but I did
stop and think that something like __invokeStatic() would be nice.
My main rationale for wanting this was that classes can be resolved
via an autoloader, whereas functions cannot.
However, I could definitely see where this could get sticky. For example:
<?php
function MyClass() {
return true;
}
abstract class MyClass {
public static function __invokeStatic()
{
return false;
}
}
$className = 'MyClass';
var_dump($className());
?>
What would the output be in a case like this? Right now, while it's
horrible practice to share names across functions and classes, they
don't actually share the same namespace. Something like
__invokeStatic() would make it ambiguous in some cases (like above),
so I'm not really sure how that could be resolved.
--
Evan Coury