> No and no. __call is not called for ctors, for obvious reasons (__call is an
> object method, and before ctor is done the object is not ready). It was
> always this way.

It is called from constructors, just not *for* constructors:

class test {
    public static function __callStatic($name, $args) {
        printf("Static: %s\n", $name);
    }
    public function __call($name, $args) {
        printf("Parent Instance: %s\n", $name);
    }
}

class test2 extends test {
    public function __construct() {
        $this->bar();
        parent::__construct();
    }
    public function __call($name, $args) {
        printf("Instance: %s\n", $name);
    }
}
$foo = new Test2();

Results in:
Instance: bar
PHP Fatal error:  Cannot call constructor in...

While I do agree that it *shouldn't* call __call/__callStatic for
constructors, it does for other methods...

>> I'd rather see calls to non-existent methods generate a catachable
>> fatal error (rather than a hard fatal error that's currently thrown).
>
> Personally, I like this "catchable fatal error" business less and less. It's
> an awkward way of doing an exception with all exception downsides and none
> of the upsides...

That's fair, but if we buy that, let's have at least an option to
convert all errors to exceptions.  That way there are no "catchable
errors", just exceptions for errors over a specified level (E_WARNING
for example)...

>> But silently ignoring a called function, something just doesn't sit
>> right about that...
>
> We're already doing it :) Try:
> class Foo {}
> $a = new Foo();
>
> You just ignored a non-existing ctor.

I guess that's fair.  I just don't care for special-case logic in
general.  It generates too many edge-cases.  That's not saying this is
worth it or not, but just my preference...

Anthony

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to