Is it possible to “escape” a method name in PHP, to be able to have a method name that clashes with a reserved keyword?

喜你入骨 提交于 2019-12-01 19:23:28

With variable names you can use the bracket signs:

${'array'} = "test";
echo ${'array'};

But PHP does not provide a method for escaping function names.

If you want a 'user-defined' way of getting around this, check out this comment:

http://www.php.net/manual/en/reserved.keywords.php#93368

Vitaliy

You can use __call() method to invoke private or public _list() method which implements your functionality.

/**
 * This line for code assistance
 * @method  array list() list($par1, $par2) Returns list of something. 
 */
class Foo 
{
    public function __call($name, $args) 
    {
        if ($name == 'list') {
            return call_user_func_array(array($this, '_list'), $args);
        }
        throw new Exception('Unknown method ' . $name . ' in class ' . get_class($this));
    }

    private function _list($par1, $par2, ...)
    {
        //your implementation here
        return array();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!