Re: __init magic method

From: Date: Tue, 22 Jan 2013 13:03:47 +0000
Subject: Re: __init magic method
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-65083@lists.php.net to get a copy of this message
Hi, On Tue, 2013-01-22 at 12:29 +0000, Pete Boere wrote: > Has there ever been any discussion on an __init magic method for > bootstraping static properties on class load? Adding an __init method as you wish will just add complexity and gain very little. What complexity am I talking about? Well look at this single file: <?php class A { public function __init() { echo __CLASS__; } } class B extends D { public function __init() { echo __CLASS__; } } class C { public function __init() { echo __CLASS__; } } class D { public function __init() { echo __CLASS__; } } class E { public function __init() { echo __CLASS__; } } ?> What should this print? ABCDE? Then the derived class B is initialized before the base class D, which might have strange effects and make debugging hard. So maybe it is ACDEB? This makes the resolution quite complicated. On the other hand: You are showing a goos solution, which is clear and works well. PHP has the global scope, we don't force everything into classes and then create Java-style static{}-madness. johannes

« previous php.internals (#65083) next »