Re: [PHP-DEV] constructors are callable as regular functions.

2009-07-02 Thread Kalle Sommer Nielsen
2009/7/2 troels knak-nielsen : > [snip] ... - I don't remember ever > seen __construct() called directly. Its commonly done when extending reflection for example, or to populate the Exception class constructor when extending it: code = (integer) $code; parent::__construct($message);

Re: [PHP-DEV] constructors are callable as regular functions.

2009-07-02 Thread Greg Beaver
troels knak-nielsen wrote: > On Thu, Jul 2, 2009 at 4:47 PM, Edward Z. Yang wrote: >> Excerpts from troels knak-nielsen's message of Thu Jul 02 10:14:18 -0400 >> 2009: >>> I would have expected the second call to __construct() to yield an error. >> Why should it? Especially since this is idiomatic

Re: [PHP-DEV] constructors are callable as regular functions.

2009-07-02 Thread Edward Z. Yang
Excerpts from troels knak-nielsen's message of Thu Jul 02 10:55:48 -0400 2009: > I understand that. It's not a technical issue - It's more a matter of > language semantics. Constructors are used for initializing state on an > object. Basically, this behaviour makes it impossible to implement > immu

Re: [PHP-DEV] constructors are callable as regular functions.

2009-07-02 Thread troels knak-nielsen
On Thu, Jul 2, 2009 at 4:47 PM, Edward Z. Yang wrote: > Excerpts from troels knak-nielsen's message of Thu Jul 02 10:14:18 -0400 2009: >> I would have expected the second call to __construct() to yield an error. > > Why should it? Especially since this is idiomatic code: > > class A { >  public fun

Re: [PHP-DEV] constructors are callable as regular functions.

2009-07-02 Thread Edward Z. Yang
Excerpts from troels knak-nielsen's message of Thu Jul 02 10:14:18 -0400 2009: > I would have expected the second call to __construct() to yield an error. Why should it? Especially since this is idiomatic code: class A { public function __construct($a) { $this->a = $a; } } class B extend

Re: [PHP-DEV] constructors are callable as regular functions.

2009-07-02 Thread Kalle Sommer Nielsen
2009/7/2 troels knak-nielsen : > Has this been discussed before? In that case, was it decided to go > with this behaviour or is it purely accidental? Are there perhaps some > implementation issues in preventing the second call to __construct()? Magic methods can always be called directly because t

[PHP-DEV] constructors are callable as regular functions.

2009-07-02 Thread troels knak-nielsen
I just realised that the following is valid php code: class Foo { function __construct() { echo "constructor called\n"; } } $f = new Foo(); $f->__construct(); Output: constructor called constructor called I would have expected the second call to __con