Re: New RFC draft "static class constructor"

From: Date: Tue, 14 Apr 2015 14:33:21 +0000
Subject: Re: New RFC draft "static class constructor"
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-85804@lists.php.net to get a copy of this message
Hi Johannes, On 13 April 2015 at 13:37, Johannes Ott <mail@deroetzi.de> wrote: > Hi, > > finally I managed to do my first RFC draft. > > https://wiki.php.net/rfc/static_class_constructor > > I hope I have done everything correct so far and I'm looking forward to > your feedback on it. Here is some feedback then: From the RFC: > - Trigger for “magic” method call: First call to class, either first call to > __construct(...) or first call to any public or protected static method or property of the class I don't think this doesn't cover all cases that it needs to. For example calling unserialze on some data that results in a class that has this static initializer should mean that it would be invoked? Similarly ReflectionClass::newInstanceWithoutConstructor also creates a class in a way that isn't covered in the RFC, but presumably should be. From the RFC. > the static class constructor should be able to throw a catchable Exception > for user error handling, if it is not possible to initialize. The open issue for > me is, what the behavior on recalling the static class constructor afterward is. > There are two possible behaviors I do not know which one I really would prefer so far. You missed the third and in my opinion correct one; the static initializer would only ever be called once. If the programmer catches the exception and forces the program to continue, that is their own problem. Adding complexity to a language to try to work around programmers ignoring exceptions is not a good idea. I think the RFC needs to be clearer in the specification of the order that static initialization is called in. e.g. class B extends class A. Both A and B have static initialization blocks. When a user calls `new B()` which static initialization block is called first? cheers Dan

« previous php.internals (#85804) next »