Public Function Addhost ($groupId, $nodeId = "Node_0", $role = "Master", $hostConfig) { //...}
It's always been a must in my image. The parameter is defined before the optional parameter, the above code is seen in the lotusphp source, how to define how to use it?
Reply content:
Public Function Addhost ($groupId, $nodeId = "Node_0", $role = "Master", $hostConfig) { //...}
It's always been a must in my image. The parameter is defined before the optional parameter, the above code is seen in the lotusphp source, how to define how to use it?
function test ($a, $b = 3, $c = 4, $d) {echo $a. $b. $c. $d ;} Echo Test (4, "", "", 9);//print result//49echo test (4, NULL, NULL, 9);//Print result//49
In fact $b = 3, the default value of $c = 4 will never be set successfully.
If the fourth parameter is a required parameter, then the function must have more than four arguments when it is used, at which point the default parameter is meaningless.
1. Your impression is not correct, the required parameters and optional parameters are not sequential, do not need to put optional parameters in the last
2. Lotusphp's Addhost () method is designed so that the main reason is that group, node, role is progressive at the conceptual level, and reverse order is logically detrimental to memory, and config
3. The calling method is Addhost ("Global_group",, Array ("host" = "127.0.0.1"), and more call methods see lotusphp/unittest/db/ rightwaytouse.php
Upstairs positive solution, PHP does not pay attention to the default parameters of the location, but the call can not be separated, such as
function test ($a, $b =3, $c =4, $d)
{
echo $a. $b. $c. $d;
}
echo Test (1,2,3,5);//Can be
echo Test (1,,, 5);//Error