Source Code:
(back to article)
<?php class MyClass { public $myProperty = "Hello, world!"; } $object = new MyClass(); $propertyName = 'myProperty'; $propertyValue = $object->{$propertyName}; // use the ->{} operator to access the property dynamically echo $propertyValue; // Output: Hello, world!
Result:
Report an issue