Graham
Graham

Reputation: 49

Cannot use 'String' as class name as it is reserved

error message

I want Generates a random string.And my develop environment is xampp with php7.0.9. because of references a String class, I got that error.

Upvotes: 1

Views: 16042

Answers (4)

Ayoub Bousetta
Ayoub Bousetta

Reputation: 97

If it's a Cakephp project on a PHP 7+ version update your lib folder

Upvotes: 1

Iyke Perry
Iyke Perry

Reputation: 331

is this a cakephp project on php 7, you should just download the cakephp 2.8 and copy the lib folder from it and replaced to my project.

and Problem Solved

Upvotes: 8

Nabeel Khan
Nabeel Khan

Reputation: 3993

You're using a class to do this probably. However when you named this class, you named it String.

PHP and other languages have reserved terms that are for internal functions and variables only. We can't use them.

Simply change the classname to something else and it will work normally.

Upvotes: 1

Mahesh Gareja
Mahesh Gareja

Reputation: 1812

String is reserved keywords. you can't use String as class names in PHP 7. change it to any other name. like Sting_type.

Upvotes: 1

Related Questions