-2 php constructor
我试图通过$_GET
参数填充类中的私有数据成员.
这是可能的,还是构造函数处理起来太复杂了?
/myfile.php?pid=f3f3rs2
:
class getvalue{
private $pid;
function __constructor(){
$this->pid=$_GET['pid'];
}
public function get(){
//if set
return $this->pid;
}
}
$me=new getvalue();
echo $me->get();
Run Code Online (Sandbox Code Playgroud)
已解决 - __construct
输入错误.
如果它不起作用,可能是因为你已经命名了这个功能
__constructor()
Run Code Online (Sandbox Code Playgroud)
当正确的名字是
__construct()
Run Code Online (Sandbox Code Playgroud)