Am 12.03.2015 18:56 schrieb "Rowan Collins" <rowan.coll...@gmail.com>:
>
> Johannes Ott wrote on 12/03/2015 17:05:
>
>>>> So doing a null check each time
>>>> is a overhead of calculation which can be avoided with this static
>>>> constructor pattern.
>>>
>>> Presumably the engine would need to perform some implicit equivalent of
>>> "if ( ! self::$initialised )" on each call to decide if the static
>>> constructor needs to be called or not, so the overhead is not completely
>>> eliminated.
>>>
>> Yes you are right but I think it can be done more efficiently inside the
>> interpreter using some struct flags then have to parse each time inside
>> a coded part in the application.
>
> Yes, point taken.

I don't think such a flag is neccessary at all. Any class. at the moment,
comes from one or another file that is included / required. And all of the
code in these files outside the class definition, is then immediately
executed. The only thing neccessary would be to check, just before that
execution begins, which of the new classes have such an initializer method,
and then call that, before the execution of the file itself begins.
Incidentally that is something that cannot be emulated with the
autoloader-does-it approach, because the autoloader can only do that after
the include/require is complete - i.e. code within the file will not yet
see the class as initialized (in that approach).

(I wrote "at the moment" above,  because the currently proposed anonymous
class thing would need extra thought when the anonymous class has such an
initializer method...)

best regards
  Patrick

Reply via email to