Re: Any chance of having __invokeStatic()

From: Date: Mon, 28 Nov 2011 20:45:05 +0000
Subject: Re: Any chance of having __invokeStatic()
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-56659@lists.php.net to get a copy of this message
On Mon, Nov 28, 2011 at 1:11 PM, Nikita Popov <nikita.ppv@googlemail.com> wrote: > 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

« previous php.internals (#56659) next »