FAQ
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"

Search Discussions

  • Nikita Popov at Nov 28, 2011 at 8:11 pm
    How would this be different from defining a function MyClass?

    Nikita

    On Mon, Nov 28, 2011 at 9:02 PM, Dmitri Snytkine
    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
  • Evan Coury at Nov 28, 2011 at 8:45 pm

    On Mon, Nov 28, 2011 at 1:11 PM, Nikita Popov 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedNov 28, '11 at 8:02p
activeNov 28, '11 at 8:45p
posts3
users3
websitephp.net

People

Translate

site design / logo © 2022 Grokbase