I'm facing an issue while working with PHP and I could really use some assistance.
I'm trying to access a specific property within an object, but I keep getting the error "cannot use object of type stdClass as array". It seems like PHP isn't recognizing my object as an array, which is causing this error.
Here's a snippet of my code for reference:
$obj = new stdClass();
$obj->name = "John";
$obj->age = 25;
$value = $obj['name']; // This line gives me an error
I expected this code to retrieve the value of the "name" property from the $obj object, but it's throwing an error instead.
Could someone please help me understand what's going wrong here? How can I access the properties of an object in PHP without encountering this error?
Any help would be greatly appreciated!