I have a recursively defined function called getPropertyValue($object, $property) that returns false if $property doesn't exist at an arbitrary depth into $object, and the value corresponding to the first $property found inside $object otherwise. It is essentially a generalized version of PHP's built-in function property_exists()
I want to make this method chainable, and I know that to do this, I would simply return a reference to the class instance ($this) in the method, but I am already returning, as I mentioned above, the value corresponding to the first $property found inside $object.
How can I make this method chainable while still returning this value? I'm thinking a possibility is to return an object containing both $this and the value of that property/false, if it is found/not found, respectively. Is this a viable approach? What would be the best way to achieve chainability in this context?
Thanks very much.