Re: New RFC draft "static class constructor"

From: Date: Mon, 13 Apr 2015 15:23:24 +0000
Subject: Re: New RFC draft "static class constructor"
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-85781@lists.php.net to get a copy of this message
Hi, On Mon, 2015-04-13 at 15:37 +0200, Johannes Ott wrote: > 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. In my opinion this makes the language way more complex as there are more places which "suddenly" execute code but solves a small problem compared to that. (Which actually is an issue many people would suggest to avoid completely instead of ennobling this with a language feature. Why am I saying it makes the language more complex? - Your proposal seems to miss mentioning when exactly the method is executed. what is the output of a.php: <?php echo 'A: '.__FILE__.':'.__LINE__."\n"; class A { static function __static() { echo __CLASS__.'::'.__METHOD__."\n"; } } echo 'B: '.__FILE__.':'.__LINE__."\n"; class B { static function __static() { echo __CLASS__.'::'.__METHOD__."\n"; } } echo 'C: '.__FILE__.':'.__LINE__."\n"; ?> b.php: <?php echo 'D: '.__FILE__.':'.__LINE__."\n"; C::$foo = 23; echo 'E: '.__FILE__.':'.__LINE__."\n"; include 'a.php'; echo 'F: '.__FILE__.':'.__LINE__."\n"; class C { static $foo = 0; static function __static() { echo __CLASS__.'::'.__METHOD__."\n"; } } echo 'G: '.__FILE__.':'.__LINE__."\n"; class D extends B { static function __static() { echo __CLASS__.'::'.__METHOD__."\n"; } } echo 'H: '.__FILE__.':'.__LINE__."\n"; ?> Mind that in b.php we make use of class C above the declaration, which we can do as C is a simple class and can be bound early during compilation. Class D however can only be bound during run-time, after including a.php, which happens after C was already used. johannes

Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
« previous php.internals (#85781) next »