Skip to content

Is PHP's __call() Used When No __construct is Present?

Jan 11, 2009 1 min read #php

This post is more than 18 months old. Technology changes quickly, so some of this content may be out of date (but that's not always the case). Please verify any technical or programming information against the current release.

Simple enough question. Let’s check out some test code:

class TEST
{
  public function __construct($arguments)
  {
    print "constructed with: {$arguments}";
  }
 
  public function __call($name, $arguments)
  {
    print "called {$name} with: {$arguments}";
  }
}
 
new TEST('hi');
php

Ran the first time, the output was:

constructed with: hi
output

Ran without a constructor?

BLANK. __call is not called.

Now we can all sleep at night! whew!