【发布时间】:2012-08-28 20:49:46
【问题描述】:
我有一个 PHP 类,它可以包含一个自己类型的数组,这个类还有一个名为 hatch() 的函数,当我为其中一个数组项调用它时,它会给我一条消息,你不能调用该函数。我这样称呼它
$this->arrayLikeThis[$i]->hatch();
但是我创建了一个外部函数来孵化对象,但我喜欢这样称呼它。我知道我可以调用类的var_dump() 的任何函数是这样的:
object(web\ui\structure\tag)#1 (4) {
["name"]=>
string(4) "meta"
["type"]=>
int(1)
["attributes"]=>
array(2) {
[0]=>
object(web\ui\structure\attribute)#2 (2) {
["attributeName"]=>
string(7) "content"
["attributeValue"]=>
string(24) "text/html; charset=utf-8"
}
[1]=>
object(web\ui\structure\attribute)#3 (2) {
["attributeName"]=>
string(10) "http-equiv"
["attributeValue"]=>
string(12) "Content-Type"
}
}
["childNodes"]=>
array(0) {
}
}
【问题讨论】:
-
您的代码在哪里,确切的错误是什么?
-
var_dump($this->arrayLikeThis[$i]);的输出是什么? -
根据您发布的输出,我可以看出您仅在
arrayLikeThis['attributes']数组中拥有对象 -
你能把你创建对象的代码贴出来吗?
标签: php oop class inner-classes function-call