Created
December 28, 2013 21:26
-
-
Save tanrax/8164393 to your computer and use it in GitHub Desktop.
PHP: Varios constructores (Multiconstructor)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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