Investigate some issues related to the parameters in PHP language. The issues ar
ID: 3720116 • Letter: I
Question
Investigate some issues related to the parameters in PHP language. The issues are
Parameter Correspondence (positiononal, keyword, combination)
Formal Parameter Default Values
Variable Number of Actual Parameters
Parameter passing methods
Write simple programs clearly illustrating the design decisions for PHP. Discuss the results of execution of your programs. Appropriately comment your source to explain your example and why your example is appropriate for this homework
I need you to write simple programs regarding each issue. Please add little comments about which issue which program corresponds to, thank you
Explanation / Answer
Issues related to the parameters in PHP language:
1. Parameter Correspondence (positiononal, keyword, combination)
a. Positional parameters depicts the correspondence between formal (parameters which appear in definition) and actual parameters (parameter appear in call) that determined by the position in the list of parameter. This method is safe and effective since 1 st actual parameter is bound to 1st formal parameter and so on.
example:
int OurFun( int first, double second)
//below represents the code in calling function
OurFun(3 , 6.9);
//here order matters. 3 is integer and 6.9 is double.
b. Keyword parameters depicts the correspondence that determined by a keyword which is a name of the formal parameter. To this actual parameter is bounded. Here one advantage is that, parameters able to placed in any order. So parameter correspondence error is less here. But the demerit of this correspondence is that name of formal parameter has to be known.
example:
Calc(long=givenlength, list=givenarray, value=givenval)
//here parameters can occur in any order., or even can mix the parameters such as
Calc(givenlength,list=givenarray, value=givenval)
c.Combination parameters
here combination of parameterscan be used.
2. Formal Parameter Default Values
In PHP language, formal parameters (parameters which appear in definition) are able to posses default values (if actual parameter (parameter appear in call) is not passed)
In PHP, passing arguments by value (as default), passing by reference, and default argument values are supported.
Default arguments can only follow arguments:
example:
Since default arguments only follow arguments,
3. Variable Number of Actual Parameters
Suppose a PHP function takes a variable number of arguments (using func_num_args() and func_get_args()), but the number of arguments that need to pass the function depending on the length of one array. There is a way to call a PHP function with a variable number of arguments.
Suppose function is as below:
We are able to bundle parameters into an array as below:
after that call the function :
then the result will be:
answer will be the count of parameters which is 3 here.
4. Parameter passing methods
a. Passing parameters by value
-parameters can be a variabe or value.
-any data can be passed as value
-function receives the value in correct order.
example:
function Profile($name, $age)
{
echo "my name is:".$name;
echo "my age is:".$age;
}
Profile(21,Alice);// receive the value in correct order
b. Passing parameters by value and reference:
-we may pass right number of values.
sometimes, we pass more no;of values and the sametime not remember to assign variables to some of it, function will not consider those left out values.
Function will assign "NULL" for missed values.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.