3v4l.org

run code in 300+ PHP versions simultaneously
<?php //return $this->has_many('Post'); class Foo{ public static $has_manyhg = "Post"; public static $age = "18"; private static $city = "Boston"; public $r=9; public static $has_many = "Post"; public function has_many($a){ return 'hola'; } function get_relationship($val) { $class = new ReflectionClass('Foo'); $staticProperties = $class->getStaticProperties(); $object=new Foo; $model = ucwords(substr($val, 4)); foreach ($staticProperties as $propertyName => $value) { if(preg_match('/^(has_many|age)$/', $propertyName) && $value == $model) { return $object->{$propertyName}($model); } } } } $foo = new Foo; echo $foo->get_relationship('get_post'); ?>

preferences:
34.71 ms | 402 KiB | 5 Q