Re: __init magic method
| From: | Marco Pivetta | Date: | Tue, 22 Jan 2013 15:52:33 +0000 |
| Subject: | Re: __init magic method | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-65088@lists.php.net to get a copy of this message | ||
@Pete just FYI, PSR-1 excludes that such a logic should exist in a loaded
file:
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md#23-side-effects
Not sure if you are interested in following the FIG on these ideas, but the
guideline makes actually sense.
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
On 22 January 2013 16:39, <nathan@starin.biz> wrote:
> I am actually going to +1 this idea I thought about discussing it, but
> opted out of it because classes are most often in their own file and if you
> need to do some static binding you can do it at the end of the file after
> the class definition. However, I do believe this idea would make it easier
> to extend classes and make the code look much cleaner.
>
> @Johannes In your example I'd say it would be ADBCE because I would say it
> should work like as if you had each one in it's own file autoloading them..
> (also I believe the function would be static)
>
> One of the potential problems I can see is the visibility
> (public/private/protected) of the function as it'd likely need to be public
> because it could never be auto-executed if anything else.
>
> Software Developer
> Nathan Bruer
>
> -----Original Message-----
> From: Johannes Schlüter [mailto:johannes@php.net]
> Sent: Tuesday, January 22, 2013 7:04 AM
> To: Pete Boere
> Cc: internals@lists.php.net
> Subject: Re: [PHP-DEV] __init magic method
>
> 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
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List To unsubscribe,
> visit: http://www.php.net/unsub.php
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>