php - 在 php 中不能有名为 default 的函数

标签 php class function default

好吧,这是非常出乎意料的,这让我很恼火。我的所有类(class)中都有名为 default() 的函数。但是,由于某种原因我不能调用它。我猜这是因为 switch 语句中的“default:”(我根本不使用它)。

我真的不能在 php 中命名我的函数 default() 还是我做错了什么?

这是错误:

Parse error: syntax error, unexpected T_DEFAULT, expecting T_STRING in 
C:\Users\Jinxed\Desktop\WebTrgovina\app\c\Controller.c.php on line 8

这里是有问题的代码:

<?php
abstract class Controller {
    protected $view;
    function __construct() {
    }
    abstract function default();
    function getView(){
        return $this->view;
    }
}

当我将 default 重命名为其他名称时代码工作正常,但这很烦人,是否有任何解决方案可以将函数命名为 default()?

最佳答案

default 是 PHP 中的保留字。

这是列表:http://www.php.net/manual/en/reserved.keywords.php

关于php - 在 php 中不能有名为 default 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10395930/

相关文章:

android - 动态按钮和 OnClickListener

c++ - 为什么我在执行以下代码时出错?

python - 从python中的函数返回不同的数据类型

基于 PHP 文本的游戏时间流逝

php - 我应该什么时候关闭数据库连接?

C# 代码 php 等效 md5 哈希

python - Python 中的元类和语法

Swift - 在带有可选参数的泛型函数中将 Nil 作为参数

c++ - 如何理解 "Pass By Reference Within a Function"w3schools示例?

php - While循环基于关联数组php?