douchen3562 2012-07-02 15:39
浏览 24
已采纳

PHP:从另一个函数调用函数(超出范围?)

I'm having a problem creating webservices through nuSOAP (although i believe my problem has nothing to do with it)

What i'm trying to do:

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;
}

I'm getting the following error:

Call to a member function toDTO() on a non-object

and both var_dump($val) and is_callable are returning the expected (the object and true, respectively) from what i've been seeing online, it appears i have a out of scope problem... but for some reason i don't seem to get my head around it :P

Thanks in advance

EDIT: well just check that apparently i don't understand is_callable either because i always get 1 as the result... EDIT2: i'm using php-activerecord if that helps in any way

  • 写回答

3条回答 默认 最新

  • douxu3315 2012-07-09 11:33
    关注

    Okay so i figured out the problem... thanks for all the help! I was calling toDTO of another object inside toDTO... problem was that object could be a null! So a simple if(object==null) solved the problem!

    Thanks again!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!