Can I use PHP reserved names for my functions and classes?

后端 未结 6 602
时光说笑
时光说笑 2020-11-28 15:50

I\'d like to create a function called \"new\" and a class called \"case\".

Can I do that in PHP?

6条回答
  •  情歌与酒
    2020-11-28 16:20

    Along the lines of what Benjamin mentioned, there is an interesting use of "clone", (which is reserved) in this class, line 545

     public function __call($method, $args)
    {
        if ('clone' == $method) {
            return call_user_func_array(array($this, 'cloneRepository'), $args);
        } else {
            $class = get_called_class();
            $message = "Call to undefined method $class::$method()";
            throw new \BadMethodCallException($message);
        }
    }
    

提交回复
热议问题