On Mon, 2 Sep 2019 at 15:03, Christian Schneider <cschn...@cschneid.com> wrote:
>
> Please don't shoot this down just because you are not the target audience of 
> such a feature

That is always good advice.

When you draft the RFC, I strongly recommend coming up with a line of
reasoning of why creating static versions of functions like this:

class Foo {
    static function createFromXml($html) {
        $instance = new static();
        $instance>loadXml();
        return $instance;
}

    function loadXml($html) {
        //...
    }
}

Are such a terrible burden, that keeping the mixed mode calling is a
desirable thing. I say that as I think it would need a strong
justification rather than just "it's something that could be done".

In particular, there are tools like
https://github.com/rectorphp/rector that I understand could be used to
do this automatically, at least for userland code.

Also(, without checking to see if it's feasible,) to me a less
surprising approach would be to allow static and instance methods to
be declared separately with the same method name.

class Foo {
    static function loadXml() {
        echo "I am static method\n";
    }

    function loadXml() {
        echo "I am instance method\n";
    }
}

Foo::loadXml();
(new Foo())->loadXml();

// output is
// I am static method
// I am instance method

Although that doesn't meet your goal of allowing seamless upgrades, it
seems like a better approach to allowing that sort of thing in
general. At least in the sense of, if I had to explain this capability
to a junior programmer, explaining that the static method is used when
called statically, and the instance method is used when called on an
instance, would be easier to explain that '$this' might or not be
there.

cheers
Dan
Ack

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to