dongshai1944 2010-12-14 22:40
浏览 24
已采纳

PHP - 获取对象父级

I have a function that is called like this:

foo($object->ID);

and in the function I need to somehow select $object if $object->ID is passed as a variable.

function foo($id = NULL){
  if($id != NULL) ... // here I want to get $object
  else ...
}

How can I do this?

  • 写回答

4条回答 默认 最新

  • dongmaomou4117 2010-12-14 22:44
    关注

    If I understand what you're asking correctly, why not just pass the object itself by ref?

    function foo(&$obj)
    {
        if($obj != NULL && $obj->ID != NULL)
        {
           // ...process your stuff 
        }
    }
    

    My PHP's pretty rusty, but I'm fairly sure that's how you pass by ref...

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

报告相同问题?