Overloadable constructors?

liunx

Guest
Having the ability to overload a constructor would be so hot! Does it have it?

Also, in the Changes in the PHP 5 / Zend Engine 2.0 (<!-- m --><a class="postlink" href="http://www.php.net/zend-engine-2.php">http://www.php.net/zend-engine-2.php</a><!-- m -->) page, it talks about overloadable method calls. It says Both method calls and property accesses can be overloaded via the __call(), __get() and __set() methodsHow is that overloading? The example doesn't even address overloaded methods or constructors.

Why would they use __construct() instead of the name of the class like in PHP 4 (or Java/.NET/C++)?

-a9No. Having different constructors with different signatured would be tricky to do in a loosely-typed language like PHP. does new Foo($bar) refer to Foo's constructor __construct($integer_parameter) or the constructor __construct($string_parameter)?

__get() and __set() are used to alter the behaviour when you use $foo = $object; or $object = $foo respectively (where $object is the object with the __get() and __set() methods). It's overloading assignment. $object->__call('wibble') is called whenever $object->wibble() is used in the code (whether or not $object has a method called wibble()). You're free to write any code you want in __get(), __set(), and __call(). You could, for example, perform different tasks depending on the types of the arguments passed to those methods.
 
Back
Top