On 14 April 2015 at 17:39, Johannes Ott <m...@deroetzi.de> wrote:
> Am 14.04.2015 um 16:33 schrieb Dan Ackroyd:
>
>> Here is some feedback then:
>>

Johannes Ott wrote:
> But in the new draft (v0.4) I'm preparing at the moment I'll try to
> formulate the trigger "first call" more common by comparing it to the
> same trigger for __autoload function.

Hmm. The language will need to be quite clear then - sometimes classes
are autoloaded when they aren't instantiated. e.g. for just normal
reflection of classes, the class is autoloaded if it isn't already
present, or some people may autoload all the things ahead of time, to
avoid any delay when responding to a request.

Johannes Ott wrote:
>Danack wrote:
>> You missed the third and in my opinion correct one; the static
>> initializer would only ever be called once.
> I think this is suggested behaviour 1, isn't it?

I read that section very differntly.

"On recall of the static class constructor a fatal error is raised to
ensure it is only called once and initialized before exception was
thrown properties will not be reinitialized."

I read that as it implies that it would be possible to call the static
initializer again, and in that case a fatal error would be thrown. If
the initializer is only ever called once, it would be clearer to say
that as a 'positive' statement, as opposed to saying a 'negative' of
what wouldn't be allowed - i.e. single statements are clearer than any
kind of double-negative statements.

Johannes Ott wrote:
>Danack wrote:
>> I think the RFC needs to be clearer in the specification of the order
>> that static initialization is called in.
> Because inheritance by using keyword
> extends is already a first call to class A.

tbh, it's quite likely that looking at Java or some other language
that has static initializers and copying that behaviour for precedence
could be the best choice.

However the behaviour might not be mappable directly, due to
differences in PHP's inheritance and class model, in particular the
late static binding.

class A {
    static function __staticInit() {
        static::foo();
    }

    static function foo() {
        echo "This is A::foo\n";
    }
}

class B extends A {
    static function foo() {
        echo "This is B::foo\n";
    }
}

B::__staticInit(); //Output is 'This is B::foo'

It's pretty easy to imagine some cases where there are circular
dependencies....so the RFC would need to be precise about exactly what
the rules are.

cheers
Dan

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

Reply via email to