Since the data types are not set in a strict sense, you can do things like adding a string to an integer without causing an error. PHP automatically associates a data type to the variable, depending on its value. If data type of a variable used in function’s algorithm does not match while calling function with arguments, desired result cannot be found and program error will occur.įor example, in the above program, notice that we have not told PHP which data type the variable is. So, we should careful enough while calling function with arguments. So, if we forget to pass value at function calling, we get a result rather error message.ĭeclaring Variable Type in Function ParameterĪs I told in PHP data types and variables discussion, PHP is a loosely typed programming language. In this example we have defined function’s default argument value at function declaration. The following program is a simple example of assigning local variable’s default value at the time of function declaration. If we assign local variable’s default value, no chance to gets error message if we forget to assign value at function calling. In PHP programming it is possible to assign local variables default value at the time of function and local variable declaration which is known as assigning function default argument value. Assigning Function Default Argument Value To make error free coding, we can assign local variables default value at the time of function and local variable declaration. In this example, the value of function parameter must assign at function calling otherwise PHP compiler will show an error message. Here, two local variables $a and $b have been declared as function parameter and assigning variable value at the time of function calling.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |