PHP: Receiving Function Arguments without declaring any parameters in prototype!
By Nilesh - July 1st, 2008
Tagged:
As you know, we usually declare functions in PHP like this -
function foo($arg1, $arg2) {
// code
}
This leads to PHP-error when one of the argument is missing. To deal with this, we have an alternate method. We shall NOT declare ANY arguments in the prototype. Then we'll use func_get_args() to get all the arguments passed to function in an array. Further we can manipulate the array as we want.
function foo() {
$args = func_get_args();
}
When you will call foo(1,2,3) then $args[0] = 1 ; $args[1] = 2 and so on.
This way you can prevent PHP-Errors and have custom errors.
To handler PHP-Errors I suppose there does exist an function to set a custom handler for PHP-Errors. This is just an alternate method ;)
Trackback URL for this post:
http://www.itech7.com/trackback/82












Comments
Post new comment