0

I want to access a property in an object by using $response->audit->id. I have placed audit->id in a variable and acessed it as $response->$str but PHP is escaping the html into &gt. I get the following exception.

Undefined property: stdClass::$audit->->id

I've tried htmlspecialchars_decode and html_entity_decode but in vain.

Lalith Mohan
  • 3,836
  • 5
  • 21
  • 36
  • 3
    Please show relevant code. – u_mulder Jan 23 '17 at 20:33
  • 6
    No matter who escaped what (PHP didn't), you cannot have an object or array expression in a string variable and expect varvars to resolve them. – mario Jan 23 '17 at 20:34
  • A good approach is to use dot notation and a library like Symfony PropertyAccess – rogeriolino Jan 23 '17 at 20:37
  • PHP has dot notation? @rogeriolino – Derek Pollard Jan 23 '17 at 20:40
  • You probably are looking for something like http://php.net/manual/en/language.variables.variable.php and possibly http://stackoverflow.com/questions/20760622/accessing-object-properties-drilling-down-without-array-conversion/20760687?noredirect=1#comment31113530_20760687. I'm with @mario, PHP ain't escaped nothing unless you told it to or use external code that does. – The Humble Rat Jan 23 '17 at 20:42
  • No @Derek, using dot notation as string value. Then parse it using ProcessAccess. Ex: `$str = 'audit.id'; $accessor->getValue($response, $str);` – rogeriolino Jan 23 '17 at 20:44
  • http://stackoverflow.com/questions/41594358/how-can-i-access-a-deep-object-property-named-as-a-variable-dot-notation-in-ph/41595663#41595663 – AbraCadaver Jan 23 '17 at 20:55

0 Answers0