0 php
class saySomething {
var $helloWorld = 'hello world';
function sayHelloWorld($helloWorld)
{
echo $helloWorld;
}
}
$saySomething = new saySomething();
$saySomething->sayHelloWorld();
Run Code Online (Sandbox Code Playgroud)
上面给出了这个错误:
Warning: Missing argument 1 for saySomething::sayHelloWorld(), called in C:\xampp\htdocs\test.php on line 15 and defined in C:\xampp\htdocs\test.php on line 7
Run Code Online (Sandbox Code Playgroud)
因为你缺少saySomething :: sayHelloWorld()的参数1.定义函数时,将其定义为具有1个必需参数.
像这样定义你的函数:
class saySomething {
var $helloWorld = 'hello world';
function sayHelloWorld()
{
echo $this->helloWorld;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
309 次 |
| 最近记录: |