So I know I can do something like this in PHP:
<?php
$x = 'a';
$a = 5;
echo $$x;
Which will output 5;
But it doesn’t work with objects/properties. Is there a way to make this code work?
<?php
class FooBar
{
public $foo;
public $bar;
public function __construct()
{
$this->foo = 'foo';
$this->bar = 'bar';
}
}
$FooBar = new FooBar();
$str = 'FooBar->foo';
echo $$str;
This might be close: