- property_exists: documentation ( source)
- print_r: documentation ( source)
<?php
class Generic
{
public static $propA = "A";
private static $propB = "B";
protected static $propC = "C";
public static function getProperty(string $property): string
{
if (!property_exists('Generic', $property)) :
return "Undefined Property";
endif;
return self::$$property;
}
}
print_r(Generic::getProperty('propA'));
echo "\n";
print_r(Generic::getProperty('somethingNotDefined'));