Widget::__call PHP Method

__call() public method

Get property value
public __call ( string $name, array $arguments ) : mixed
$name string
$arguments array
return mixed
    public function __call($name, $arguments)
    {
        $matches = array();
        if (!preg_match('/^get([A-Z][a-zA-Z0-9_-]+)$/', $name, $matches)) {
            return NULL;
        }
        // extract name
        $property = $matches[1];
        $property[0] = strtolower($property[0]);
        // lowercase 1st
        // get value from db
        $value = $this->getSetting($property);
        // get value from property
        if (empty($value) && property_exists($this, $property)) {
            $value = $this->{$property};
        }
        // get value from annotation
        if (empty($value)) {
            $value = $this->getAnnotation($property);
        }
        // get value from ini file
        if (empty($value)) {
            $value = $this->manager->getMeta($property);
        }
        // return value
        // TODO set type by property if exists
        return $value;
    }

Usage Example

Example #1
0
        return 88;
    }
    //*
    public function __call($name, $arguments)
    {
        echo "Calling instance method >{$name}<\n";
        var_dump($arguments);
        return 987;
    }
    //*/
    ///*
    public static function __callStatic($name, $arguments)
    {
        echo "Calling static method >{$name}<\n";
        var_dump($arguments);
        return "hello";
    }
}
$obj = new Widget();
$v = $obj->iDoit();
$obj->__call('iDoit', []);
$v = $obj->iMethod(10, TRUE, "abc");
var_dump($v);
$obj->__call('iMethod', array(10, TRUE, "abc"));
$obj->__call('123#$%', []);
$v = Widget::sDoit();
Widget::__callStatic('sDoit', []);
$v = Widget::sMethod(NULL, 1.234);
var_dump($v);
Widget::__callStatic('sMethod', array(NULL, 1.234));
Widget::__callStatic('[]{}', []);