Technology Programming

What Is a PHP Argument?


    • PHP was originally developed as a set of tools written in the Perl programming language, but evolved into a distinct language in its own right. A PHP program is like a Web page template. Unlike a static web page, it is not stored in its final form. The PHP program has sections that will be filled in when the program is invoked. This results in different Web pages according to the results of database fetches.

    Parameter Format

    • Parameters, like variables in PHP always start with a dollar sign ($). They follow a function name in brackets and separated by comas: my_function($a_parameter, $b_parameter). The data type of variables do not have to be declared. The compiler derives the type from the first value assigned to a variable or parameter.

    Passing Arguments

    • An argument can be a value, a variable, an array or a reference. In the example: a_function('a') the letter 'a' is the argument passed to the function. In the example a_function($a) whatever value has been placed in the variable $a is the argument to the function. However, values contained in global variables do not need to be passed as arguments because they can be made local by a "global" declaration from within the function. The value of a global variable will not be modified when it is passed to a function. However, it will if the variable is passed as a reference. This passes control of the variable and its contents to the function. This is achieved by the syntax: a_function(&$a).

    Error Conditions

    • The argument list of a function must match the number of parameters in the function declaration. Otherwise an error will occur. Function declarations may include default values for parameters, in which case, the function can be called without without arguments. However, if only some parameters are given default values in the function declaration, those parameters without default values must be listed before those with default values. In this case only arguments for those parameters without default values need to be supplied.

Leave a reply