RE: [PHP-DEV] __init magic method
| From: | Jared Williams | Date: | Wed, 23 Jan 2013 16:28:56 +0000 |
| Subject: | RE: [PHP-DEV] __init magic method | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-65115@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Pete Boere [mailto:pete@the-echoplex.net]
> Sent: 22 January 2013 12:30
> To: internals@lists.php.net
> Subject: [PHP-DEV] __init magic method
>
> 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.
>
I'd say, that using static at all isn't elegant. There is always a way
to avoid it.
Jared