PHP: Receiving Function Arguments without declaring any parameters in prototype!

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

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <h1><h2><h3><h4><h5><h6><b><i><u><style><div><span><li><ol><ul><img><s><em><strong><a><address><blockquote><table><td><tr><th><caption><p><br><pre><code><fn><footnotes><dl><dt><dd><font>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

CAPTCHA
This is to verify that you are human visitor
4 + 10 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Syndicate content
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by the Poster. Rest Copyright © iTech7.com

For License and Copyrights see http://www.itech7.com/Content-Copyrights