__init magic method
| From: | Pete Boere | Date: | Tue, 22 Jan 2013 12:29:46 +0000 |
| Subject: | __init magic method | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-65078@lists.php.net to get a copy of this message | ||
Has there ever been any discussion on an __init magic method for
bootstraping static properties on class load?
The usual solution I come up with is manually calling an init method post
class definition, which works, though I'd call it slighly less than elegant:
class Foo {
static $bar;
static function init () {
// Create $bar with expressions...
self::$bar = $bar;
}
}
Foo:init();
A custom autoloader could of course anticipate this but with systems like
composer that have a shared autoload, it'd be nicer to use those than rely
on a custom loader.
--
Pete Boere
Web Developer