Skip to content

Instantly share code, notes, and snippets.

@tanrax
Created December 28, 2013 21:26
Show Gist options
  • Save tanrax/8164393 to your computer and use it in GitHub Desktop.
Save tanrax/8164393 to your computer and use it in GitHub Desktop.
PHP: Varios constructores (Multiconstructor)
<?php
/**
* Multiconstructs
*/
class nomClass {
function __construct() {
$a = func_get_args();
$i = func_num_args();
if (method_exists($this,$f='__construct'.$i)) {
call_user_func_array(array($this,$f),$a);
}
}
function __construct0() {
echo "Arguments 0 \n";
}
function __construct1($insNom) {
echo "Arguments 1 $insNom \n";
}
}
new nomClass();
new nomClass('Mozart');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment