Source Code:
(back to article)
<?php class MyClass { public $myProperty; public function __get($property) { if (property_exists($this, $property)) { return $this->$property; } else { echo "The property '$property' does not exist in this class."; } } } $object = new MyClass(); $propertyName = 'nonExistentProperty'; $propertyValue = $object->$propertyName; // this will trigger __get // Output: The property 'nonExistentProperty' does not exist in this class.
Result:
Report an issue