0

I want to store an property->object name in a table and access in code.

What is the proper way to accomplish the following.

$patient = new stdClass();
$patient->patient_number = '12345';

$cls = 'patient';
$prp = 'patient_number';



echo 'test1 = ' . $patient->patient_number . '<br>';    
//--- this prints 12345 as expected;
echo 'test2 = ' . $$cls->patient_number . '<br>';
//--- this print 12345 as expected;
echo 'test3 = ' . $$cls->${$prp} . '<br>';
//--- this generates undefined variable patient_number;

1 Answers1

0

Use this:

echo 'test3 = ' . ${$cls}->{$prp} . '<br>';