【发布时间】:2013-02-08 16:29:50
【问题描述】:
我很难理解如何在我的脚本中创建对象......我收到此错误:
PHP Fatal error: Call to undefined function Object()
我的代码是这样的:
$block = Object(); // error here
$row['x'] = 5;
$row['y'] = 7;
$row['widthx'] = 3;
$row['widthy'] = 3;
for($i = $row['x']; $i < ($row['x'] + $row['widthx']); $i++){
if(!is_object($block[$i])){
$block[$i] = Object();
}
}
谁能解释我做错了什么?
【问题讨论】:
-
您正在寻找
new stdClass()而不是Object()。另见php.net/manual/en/language.oop5.basic.php -
我先尝试了那个方法,但我得到了
Call to undefined function stdClass() -
我也收到了
Cannot use object of type stdClass as array -
@Dave 如果你有未定义的函数,这意味着你忘记了
new关键字。$block[$i] = new stdClass()
标签: php