Okay, Lets say I have an object with properties like this:
$testObj->wind->windi // this returns a value like 100 mph
$testObj->wind->windii // this returns a value like 110 mph
I need to access a property but I don't know what property explicitly, Instead I have a string like this:
$str = 'wind->windii';
Calling predefined values works:
echo $testObj->wind->windii; //results in 110 mph
The Problem: I need a way to get the values without hard coding the actual properties:
echo $testObj->$str; //and have it result in 110 mph
I thought this was a variable variables situation but I had no luck getting that to work and after a few hours of frustration I'm asking for help
*edit: I also need to mention that the object name changes as well so we can't hard code $testObj but rather be able to take any object and any string and get it's properties
Also, bracket notation isn't working, it results in "Undefined property: stdClass::$wind->elevation"
For those following at home, this is the var_dump of $testObj
object(stdClass)#299 (2) {
["snow"]=>
object(stdClass)#315 (3) {
["elevation"]=>
string(5) "365.4"
["results"]=>
string(1) "6"
["status"]=>
int(1)
}
["wind"]=>
object(stdClass)#314 (5) {
["elevation"]=>
string(5) "365.4"
["windi"]=>
string(7) "100 mph"
["windii"]=>
string(7) "110 mph"
["windiii"]=>
string(7) "115 mph"
["status"]=>
int(1)
}
}