On 06/03/2021 12:09, Andrea Faulds wrote:
This seems reasonable, but I fear it would create a similar mess to
C++ with static initialisers, because a class constructor can do
basically anything…
That was my initial reaction, too, but it's actually pretty trivial to
do static initialisation already, thanks to the way autoloading works.
For instance if you put the below in "Foo.php", then it will be run once
the first time class "Foo" is loaded:
class Foo {
public static $bar;
}
Foo::$bar = new Whatever();
This has essentially the same effect as writing this:
class Foo {
public static $bar = new Whatever();
}
Which is absolutely horrible if Whatever's constructor has side effects,
but then most things are going to be horrible if your constructors have
side effects...
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php