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?

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...

That is not possible. You are passing a number without any information about its origin. Do this

foo($object)

function foo($object){
   if($object->ID !== null) ... // work with $object
   else ... // work with ID

}

You need to pass the object in as an argument instead of the ID.

why not:

foo($object);

and

function  foo($localObject){
  if(isset($localObject->id)){
  }
}