Re: static constructor

From: Date: Thu, 12 Mar 2015 12:33:14 +0000
Subject: Re: static constructor
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-84633@lists.php.net to get a copy of this message
Am 12.03.2015 um 12:33 schrieb Johannes Ott:
Am 12.03.2015 um 12:16 schrieb Crypto Compress:
Hello Johannes, class Foo {
     private static function __static() {
         throw new Exception("boom");
     }
} while(true) {
     try {
         $foo = new Foo;
     } catch (Exception ex) {}
} Would this code be valid?
Have to think about this issue, but on the first look I would say yes! Because the meaning of the static constructor is to do some necassary initialize for the class it should be able to throw an Exception if it cannot do it's work correctly. For example if it needs to read some configuration from a Database and is not able to connect. For the caller I although would say, that the error inside the static constructor should be catchable, for the simple fact that every Error should be catchable for user-errorhandling. What is your point of view for this? I'm open for discussion about this. Regards
If it's valid code then caching thrown exception and rethrow as wrapped-inner-exception on each subsequent access on Foo, seems feasible. I like the idea but cannot wrap my head around this.

« previous php.internals (#84633) next »