Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.7] PHP7 Error : 'String' class name is reserved #7573

Closed
aymanrb opened this issue Oct 17, 2015 · 18 comments
Closed

[2.7] PHP7 Error : 'String' class name is reserved #7573

aymanrb opened this issue Oct 17, 2015 · 18 comments
Milestone

Comments

@aymanrb
Copy link

aymanrb commented Oct 17, 2015

Today I was testing my CakePHP v2.7.5 application against PHP7 to check on its compatibility and get it ready with the final stable release of php when it arrives.

I got this error when I tried to run some migration files:

Fatal Error Error: Cannot use 'String' as class name as it is reserved in 
[.../lib/Cake/Utility/String.php, line 26]

Didn't test it over with CakePHP v3 but I guess the utility class name "String" should be changed in older versions.

@aymanrb aymanrb changed the title PHP7 Error PHP7 Error : 'String' class name is reserved Oct 17, 2015
@aymanrb aymanrb changed the title PHP7 Error : 'String' class name is reserved [2.7] PHP7 Error : 'String' class name is reserved Oct 17, 2015
@ADmad
Copy link
Member

ADmad commented Oct 17, 2015

2.x is not compatible is PHP 7. We cannot change the class name String without breaking backwards compatibility.

The class has already been renamed in CakePHP 3.x which is compatible with PHP 7.

@ADmad ADmad closed this as completed Oct 17, 2015
@ADmad ADmad added this to the 2.7.6 milestone Oct 17, 2015
@josegonzalez
Copy link
Member

You should be using the CakeText class instead of String.

@ADmad
Copy link
Member

ADmad commented Oct 17, 2015

Ah I forgot we did rename the class in 2.x too. But we don't run the testsuite for 2.x on PHP 7 (probably due to phpunit issues) so can't claim compatibility with PHP 7 even though it will probably run.

@markstory
Copy link
Member

@ADmad it is also unlikely that all the community plugins have or will switch to CakeText.

@aymanrb
Copy link
Author

aymanrb commented Oct 18, 2015

Thank you @ADmad & @josegonzalez. I didn't notice it was changed, it worked fine with CakeText now.

@markstory I totally agree with you, but changing it in the Migrations plugin wasn't a bit deal, it's only there in the Console/Command/MigrationShell.php

I know maintaining the compatibility won't always be that easy, but it's worth it, looking into the number of Cake2.x apps and the expected performance enhancements of PHP7.

Thank you all for the efforts

@abhilashlohar
Copy link

I was getting same issue.
What i did:-
I just download the cakephp 2.8 and copy the lib folder from it and replaced to my project.

and Problem Solved

@diyfr
Copy link

diyfr commented Aug 10, 2016

@abhilashlohar I have the same problem and apply your solution, but for static text (i18n) only the first character is displayed. An idea ? Works with 2.3.5
Edit 1: If i deactivate the cache, it's work !!
Edit 2: Resolved. Clear manualy the cache after upgrade CakePhp lib folder

@abhilashlohar
Copy link

@diyfr have your problem resolved ?

@ADmad
Copy link
Member

ADmad commented Aug 10, 2016

Guys this is not a help forum and your issue is unrelated to this ticket. Please take your discussion to the official forum or stackoverflow.

@diyfr
Copy link

diyfr commented Aug 10, 2016

@abhilashlohar Yes.
@ADmad sorry for the inconvenience

@chinmay235
Copy link

chinmay235 commented Nov 14, 2016

@josegonzalez thank you for your comment. I have used CakeText insted of String. Now this is working fine. But I am not sure that is right way or not.

@dereuromark
Copy link
Member

dereuromark commented Nov 14, 2016

CakeText is the right way for Cake 2.x.

@chinmay235
Copy link

@dereuromark thanks

@chinmay235
Copy link

chinmay235 commented Nov 14, 2016

@dereuromark I am getting same error. Can you please hlep me.

I am getting this error in my controller.
{
"code": 500,
"url": "\/2016\/TPO\/project\/orders\/new_order.json",
"name": "Cannot declare class CakeText, because the name is already in use"
}

tttttt

@dereuromark
Copy link
Member

It must be a dev error on your side. Make sure you only have a single CakeText class (the one CakePHP offers).

@chinmay235
Copy link

chinmay235 commented Nov 15, 2016

@derekperkins CakeText working fine. But while I am fetching data from my MySQL db. This won't work

@PiyushNagwani
Copy link

CakeText

thanks bro you don't know how much time you saved

@PiyushNagwani
Copy link

I was getting same issue. What i did:- I just download the cakephp 2.8 and copy the lib folder from it and replaced to my project.

and Problem Solved

thanks you saved my time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants