Knowee
Questions
Features
Study Tools

下面函数定义中正确的是 A $x = "OK"; function func(string $a=$x, string $b): string { return $a . $b; } B $x = "OK"; function func(string $a, string $b=$x): string { return $a . $b; } C function func(string $a="OK", string $b): string { return $a . $b; } D function func(string $a, string $b="OK"): string { return $a . $b; }

Question

下面函数定义中正确的是 A $x = "OK";

function func(string a=a=x, string $b): string {

return a.a . b;

}

B $x = "OK";

function func(string a,stringa, string b=$x): string {

return a.a . b;

}

C function func(string a="OK",stringa="OK", string b): string {

return a.a . b;

}

D function func(string a,stringa, string b="OK"): string {

return a.a . b;

}

🧐 Not the exact question you are looking for?Go ask a question

Solution

在这四个函数定义中,只有选项C和选项D是正确的。

在PHP中,函数的默认参数值必须是常量表达式,不能是变量,表达式或函数调用。

所以选项A和选项B都是错误的,因为它们试图将变量$x作为默认参数值。

选项C和选项D是正确的,因为它们的默认参数值是常量字符串"OK"。

Similar Questions

Write a note on different string handling functions

Choose the correct function declaration of  fun1() so that we can execute the following function call successfullyfun1(25, 75, 55)fun1(10, 20)

Given the following function fun1() Please select all the correct function callsdef fun1(name, age):    print(name, age)fun1("Emma", age=23)fun1(age =23, name="Emma")fun1(name="Emma", 23)fun1(age =23, "Emma")

Given the following function fun1() Please select all the correct function callsdef fun1(name, age):    print(name, age)

7.Pertanyaan #7Sel spreadsheet L6 berisi string teks "Function". Untuk menampilkan substring "Fun", sintaksis apa yang digunakan?1 poin=RIGHT(L6, 3)=LEFT(3,L6)=LEFT(L6, 3)=RIGHT(3,L6)

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.