【发布时间】:2012-07-02 15:39:21
【问题描述】:
我在通过 nuSOAP 创建 Web 服务时遇到问题(尽管我相信我的问题与此无关)
我想做什么:
function loadActiveItems() {
$list = Item::loadActive();
$ret = array();
foreach ($list as $val){
//two tests to check if i really have an object and if the toDTO method is callable
echo var_dump($val);
echo is_callable(array($val, 'toDTO'));
array_push($ret, $val->toDTO());
}
unset($val);
return $ret;
}
我收到以下错误:
Call to a member function toDTO() on a non-object
并且var_dump($val) 和is_callable 都从我在网上看到的返回预期(分别为对象和真),看来我有一个超出范围的问题......但出于某种原因我我似乎没有理解它:P
提前致谢
编辑:好吧,只要检查一下,显然我也不明白 is_callable 因为我总是得到 1 作为结果...... EDIT2:如果有任何帮助,我正在使用 php-activerecord
【问题讨论】:
-
您不应回显 var_dump() 的结果。你能发布 var_dump 的结果吗?
-
也许可以试试
foreach($list as &$val) { ... } -
@Florent
object(Item)[25] public 'errors' => null private 'attributes' (ActiveRecord\Model) => array (size=5) 'id' => int 1 'itemtype_id' => int 1 'parent_id' => null 'name' => string 'item1' (length=5) 'active' => int 1 private '__dirty' (ActiveRecord\Model) => array (size=0) empty private '__readonly' (ActiveRecord\Model) => boolean false private '__relationships' (ActiveRecord\Model) => array (size=0) empty private '__new_record' (ActiveRecord\Model) => boolean false -
@Greg nope... 这不是静态的 =( public function toDTO(){ require_once 'DTO/ItemDTO.php'; return new ItemDTO($this->id, $this-> name, null, $this->itemtype->name, $this->parent->toDTO()); }
-
@TomIngram 也没有用 =/ 还是谢谢!
标签: php oop function scope nusoap