没有不值得去解决的问题,也没有不值得去学习的技术!

Resolving the “Cannot use ‘String’ as class name as it is reserved” Error in PHP 7.0.22 and CakePHP 2.6.4

Under CakePHP 2.6.4, the error "Error: Cannot use 'String' as class name as it is reserved" is reported

1. Under CakePHP 2.6.4, the error “Error: Cannot use ‘String’ as class name as it is reserved” is reported, as shown in Figure 1.

Under CakePHP 2.6.4, the error "Error: Cannot use 'String' as class name as it is reserved" is reported
Figure 1

2. String is a reserved name in PHP 7.x, so the String class in Cake cannot be used on PHP 7.x. Upgrade to the latest 2.x version and use CakeText instead, as shown in Figure 2.
Reference URL: https://book.cakephp.org/2.0/en/appendices/2-7-migration-guide.html#utility . The String class has been renamed to CakeText, which resolves compatibility issues with HHVM and some conflicts with PHP 7+. A String class is still provided for backward compatibility reasons.

String is a reserved name in PHP 7.x, so the String class in Cake cannot be used on PHP 7.x. Upgrade to the latest 2.x version and use CakeText instead
Figure 2

3. Open the URL: https://github.com/cakephp/cakephp/tags and select 2.10.3, as shown in Figure 3.

Open the URL: https://github.com/cakephp/cakephp/tags and select 2.10.3
Figure 3

4. Rename the lib directory in the application directory to lib-2.6.4, as shown in Figure 4.

Rename the lib directory in the application directory to lib-2.6.4
Figure 4

5. Copy the lib directory from the downloaded package to the application directory, as shown in Figure 5.

Copy the lib directory from the downloaded package to the application directory
Figure 5

6. After a successful upgrade, the error has disappeared and the system runs normally, as shown in Figure 6.

After a successful upgrade, the error has disappeared and the system runs normally
Figure 6

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系