note 114138 added to functions.user-defined
| From: | lubaev | Date: | Wed, 15 Jan 2014 14:18:29 +0000 |
| Subject: | note 114138 added to functions.user-defined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198242@lists.php.net to get a copy of this message | ||
<?php
function overload()
{
$overloadFn = array();
// key = count arguments, value = callback function.
$overloadFn[0] = function() {
return print nl2br("Zero argument. \n");
};
$overloadFn[1] = function($a) {
return print nl2br("One argument. Result: $a \n");
};
$overloadFn[2] = function($a,$b) {
return print nl2br("Two argument. Result: $a, $b \n");
};
$overloadFn[4] = function($a,$b,$c,$d) {
return print nl2br("Four argument. Result: $a, $b, $c, $d \n");
};
$countArgs = func_num_args();
$valueArgs = func_get_args();
if( isset($overloadFn[ $countArgs ]) )
{
return call_user_func_array( $overloadFn[ $countArgs ], $valueArgs );
}
trigger_error("Wrong number of arguments!", E_USER_WARNING);
}
// OVERLOAD
overload(); // Zero argument.
overload(1); // One argument. Result: 1
overload(1,2); // Two argument. Result: 1, 2
overload(1,2,3); // Warning: Wrong number of arguments!
overload(1,2,3,4); // Four argument. Result: 1, 2, 3, 4
overload(1,2,3,4,5); // Warning: Wrong number of arguments!
?>
----
Server IP: 195.54.192.44
Probable Submitter: 84.17.30.45
----
Manual Page -- http://php.net/manual/en/functions.user-defined.php
Edit -- https://master.php.net/note/edit/114138
Del: integrated -- https://master.php.net/note/delete/114138/integrated
Del: useless -- https://master.php.net/note/delete/114138/useless
Del: bad code -- https://master.php.net/note/delete/114138/bad+code
Del: spam -- https://master.php.net/note/delete/114138/spam
Del: non-english -- https://master.php.net/note/delete/114138/non-english
Del: in docs -- https://master.php.net/note/delete/114138/in+docs
Del: other reasons-- https://master.php.net/note/delete/114138
Reject -- https://master.php.net/note/reject/114138
Search -- https://master.php.net/manage/user-notes.php