I am casting an array as an object and attempting to access the key (or property), but it is not working. The below code returns type 8 -- Undefined property: stdClass::$2
. I attempted to use property_exists()
, but that also failed.
$var = (object)array('1' => 'Object one','2' => 'Object two');
$num = "2";
var_dump( $var->$num );
Does anyone know why?
UPDATE: This seems to be an issue regardless if the properties are strings or integers.