- substr: documentation ( source)
- preg_match: documentation ( source)
- ucwords: documentation ( source)
<?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_manyc($a){
return 'hola';
}
}
function get_relationship($val) {
$class = new ReflectionClass('Foo');
$staticProperties = $class->getStaticProperties();
//print_r($staticProperties);
$object=new Foo;
$model = ucwords(substr($val, 4));
foreach ($staticProperties as $propertyName => $value) {
if(preg_match('/^(has_many|age)$/', $propertyName) && $value == $model) {
//return call_user_func(array($object, $propertyName.'c'), $model);
return $object->{$propertyName.'c'}($model);
}
}
}
echo get_relationship('get_post');
?>