找回密码
 新建账号

PHP Fatal error: Cannot use 'String' as class name as it is reserved

[复制链接]
php 发表于 2017/12/2 14:11 | 显示全部楼层 |阅读模式
PHP Fatal error:  Cannot use 'String' as class name as it is reserved in ThinkPHP\Library\Org\Util\String.class.php on line 13
使用ThinkPHP报错Cannot use 'String' as class name as it is reserved是因为从PHP 7.0.0开始String变成了保留关键字,用来限定函数的参数或返回值类型,报错的String.class.php使用了String作为类名。这个问题并不仅限于ThinkPHP,只要错误地使用了保留关键字都会出现类似问题。
解决Cannot use 'String' as class name的方法就是,把String改为其他名字,不要占用PHP关键字即可。除了String还有以下关键字。
int (PHP 7+) float (PHP 7+)        bool (PHP 7+) string (PHP 7+)  true (PHP 7+) false (PHP 7+) null (PHP 7+) void (PHP 7.1+) iterable (PHP 7.1+)  object (PHP 7.2+) resource (PHP 7+) mixed (PHP 7+) numeric (PHP 7+)详情可以参考PHP手册文档
  1. <?php
  2.         class String {
  3.                 //......
  4.         }
  5. ?>
复制代码
  1. <?php
  2.         class MyString {
  3.                 //......
  4.         }
  5. ?>
复制代码

手机版|轻松E站

GMT+8, 2024/3/19 12:52

快速回复 返回顶部 返回列表