获取PHP的父属性

MySuperCooLFunction($object->property1->property2->property3);

...

public function MySuperCooLFunction($args) {
   // retreive property 3
   // retreive property 2
   // retreive property 1
}

Is there anyway to do this?

This is only possible if your property-objects store their parent object in one of their own properties, since you are only passing the value of property3 to MySuperCooLFunction() I would not recommend that, though (this would lead to quite inflexible code). Why don't you pass $object to MySuperCooLFunction()? You can access all properties when working from the top down.

No, there's not a way for the function (as written) to get the values of object, property1 or property2.

When MySuperCooLFunction($object->property1->property2->property3) is called, only the value of property3 is passed as the argument. When the call is made, the interpreter resolves $object->property1->property2->property3 to the value of property3 then hands that value into the function. The function has no knowledge of how the value of the argument was found/computed.

You can not do this. When your function is invoked, you are making a copy of property3 (in case it is a simple variable) or a reference to it, but you loose the references to the rest of the parent object.

If you want to do that, you need to convert property3, and property2, and property1, into objects which have a parent field which points to the parent.

No, you probably want to do something like this instead

MySuperCooLFunction($object);
...

public function MySuperCooLFunction($object) {
   $object->property1 // retreive property 1
   $object->property1->property2 // retreive property 2
   $object->property1->property2->property3 // retreive property 3
}

if you don't want to pass $object in for some reason,

   public function MySuperCooLFunction($property1) {
       $property1 // property 1 is passed in
       $property1->property2 // retreive property 2
       $property1->property2->property3 // retreive property 3
    }

also works