<?php
$variableName = 'location->city';
// Create new variable with the name defined in variable $variableName
${$variableName} = 'Chicago';
//Outputs: string(7) "MyValue"
var_dump($location->city);
//Outputs: string(7) "MyValue"
var_dump(${'location->city'});
Warning: Undefined variable $location in /in/bFgUl on line 6
Warning: Attempt to read property "city" on null in /in/bFgUl on line 6
NULL
string(7) "Chicago"
Notice: Undefined variable: location in /in/bFgUl on line 6
Notice: Trying to get property 'city' of non-object in /in/bFgUl on line 6
NULL
string(7) "Chicago"
Notice: Undefined variable: location in /in/bFgUl on line 6
Notice: Trying to get property of non-object in /in/bFgUl on line 6
NULL
string(7) "Chicago"
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: location in /in/bFgUl on line 6
Notice: Trying to get property of non-object in /in/bFgUl on line 6
NULL
string(7) "Chicago"
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9
Notice: Undefined variable: location in /in/bFgUl on line 6
NULL
string(7) "Chicago"