php7 PHP Fatal error: Cannot use 'String' as class name
因为升级PHP7,想检测不兼容的代码,使用了工具php7ccphp7cc --level=error vendor>error.txt
File: /vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Object.php
> Line 7: [Error] Name "object" that is reserved for future use (does not cause an error in PHP 7) used as a class, interface or trait name
class Object extends \PhpParser\Node\Expr\Cast
{
}
File: /vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Bool.php
> Line 7: [Error] Reserved name "bool" used as a class, interface or trait name
class Bool extends \PhpParser\Node\Expr\Cast
{
}
File: /vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/String.php
> Line 7: [Error] Reserved name "string" used as a class, interface or trait name
class String extends \PhpParser\Node\Expr\Cast
{
}
File: /vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Int.php
> Line 7: [Error] Reserved name "int" used as a class, interface or trait name
class Int extends \PhpParser\Node\Expr\Cast
{
}
File: /vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String.php
> Line 10: [Error] Reserved name "string" used as a class, interface or trait name
class String extends \PhpParser\Node\Scalar
{
}
File: /vendor/phpunit/phpunit/tests/_files/Error.php
> Line 2: [Error] Class/trait/interface "Error" was added in the global namespace
class Error extends \PHPUnit_Framework_TestCase
{
}
File: /vendor/classpreloader/classpreloader/src/Parser/DirVisitor.php
> Line 8: [Error] Reserved name "string" used as a use statement alias
PhpParser\Node\Scalar\String
File: /vendor/classpreloader/classpreloader/src/Parser/FileVisitor.php
> Line 8: [Error] Reserved name "string" used as a use statement alias
PhpParser\Node\Scalar\String
文档也指出无效的类、接口以及 trait 命名
这些代码都在vendor下,没法直接修改吧,该如何处理好呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看了一下,应该是你这个Parser工具使用了PHP7的关键字或者是PHP的保留字来做类名,然后出错了。你这个vendor下的工具我没用过,不过作为PHP,你想改并不是不可以。
哪个地方使用到了,直接继承重写可不可以?我记得我用yii2的时候也是有个包是这样的。