Cakephp: 2.x support PHP 7.2?

Created on 20 Oct 2017  路  35Comments  路  Source: cakephp/cakephp

What is the official word on 2.x with PHP 7.2?

If it is supported, can we mention it in the docs? If it will not be supported, also mention it in the docs.

I know 2.x is old. I get that. The reason I'm going though this hassle is that 2.x will be the last version of CakePHP for us, and I want it to last as long as possible. I found no information on StackOverflow or anywhere on the Googles.

Thanks!

enhancement

Most helpful comment

Ok thanks. I've found a workaround.

composer require phpseclib/mcrypt_compat
  • Add this to composer.json. But please don't do that in a public package, only private applications.
{
  "provide": {
    "ext-mcrypt": "*"
  }
}
  • Run composer update
  • Test your application

All 35 comments

Someone just needs to make a PR to support it. Then it would be supported.

Can you confirm that it would involve:

  • Installing mcrypt and adding 7.2 to travis
  • Fix any broken tests

Anything I missed?

Tried and appveyor failed. Any idea why?

@josephzidell if you refer to this, I guess it's unrelated, cause I do not see anything related changed.

Closing as pull request #11347 is up.

7.2 as of this time is still excluded ( https://github.com/cakephp/cakephp/blob/2.x/.travis.yml#L45 ) and breaks, e.g. with

Cannot use 'object' as class name as it is reserved in [/var/www/html/vendor/cakephp/cakephp/lib/Cake/Core/Object.php, line 18]

The next 2.x release should contain 7.2 compatibility IMO

@dereuromark Looks like Object.php just does a class_alias. Seems like it could be a relatively small change to remove Object.php and replace usage with CakeObject. Good task for a first-time committer maybe.

UPDATE: Looks like the Object class was retained for plugin compat per https://github.com/cakephp/cakephp/commit/57bc0f9c457974378b708c79752a4ee1de26c389.

Since I stirred this up on IRC, there is also a warning being omitted along with the Fatal Error that dereuromark noted above that may or may not be something that the framework would want to address (vs php itself):

Error: Fatal Error (64): Cannot use 'object' as class name as it is reserved in [/var/www/html/vendor/cakephp/cakephp/lib/Cake/Core/Object.php, line 18]

Warning: Warning (2): Narrowing occurred during type inference. Please file a bug report on bugs.php.net in [/var/www/html/vendor/cakephp/cakephp/lib/Cake/Core/App.php, line 567]

For travis to run you also need to take care of the mcrypt problem:
https://travis-ci.org/cakephp/cakephp/jobs/311605746#L168

Thank you for reopening this issue. Regarding mcrypt, I would like to make it optional, to make it easy to install via composer in any environments. If I am not wrong, any features from mcrypt are not used by default. And we could implement Security::encrypt() by using the openssl extension. Probably, Security::rijndael() would be the mcrypt-specific feature.

@chinpei215 @dereuromark I think that would be a great move for long-term longevity of the 2.X series. I think we may get to a point where mcrypt is disallowed by security policy before teams are ready to sunset their Cake 2.X apps.

@stevenscg I am planning to do it in the not so distant future.

Is now everything 7.2+? Then we can close.

Is 7.2 now officially supported?

@josephzidell Our test suite is passing. I personally don't have any applications using 2.x so I cannot confirm if it works outside of the test suite.

Hi! I have installed PHP 7.2 and CakePHP 2.10.4.
Now composer update stops with the following error message:

composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - cakephp/cakephp 2.10.4 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
    - cakephp/cakephp 2.10.4 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
    - Installation request for cakephp/cakephp 2.10.4 -> satisfiable by cakephp/cakephp[2.10.4].

  To enable extensions, verify that they are enabled in your .ini files:
    - php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

This is logical, because the documentation of PHP says that mcrypt is removed in PHP 7.2.
http://php.net/manual/de/migration71.deprecated.php

When is PHP 7.2 supported by CakePHP 2.x?

You can install it via pecl, like the mysql extension that was deprecated in php 7.0

@raul338 I have no chance to install pecl on my servers.

When is PHP 7.2 supported by CakePHP 2.x?

Like I said earlier, it works now. We can't remove ext-mcrypt usage as it would break existing features. You'll have to figure out how to install mcrypt, or use --ignore-platform-reqs when installing.

Ok thanks. I've found a workaround.

composer require phpseclib/mcrypt_compat
  • Add this to composer.json. But please don't do that in a public package, only private applications.
{
  "provide": {
    "ext-mcrypt": "*"
  }
}
  • Run composer update
  • Test your application

I have mycrpt installed and I'm still getting:
PHP Fatal error: Cannot use 'object' as class name as it is reserved in cakephp/lib/Cake/Core/Object.php on line 18

Any suggestions? I'm using php 7.2 and cakephp-2.10.9.

What is the rest of your strack trace? Make sure you are not using this class anywhere.
Check your code - looks like you are, and hence it throws the exception.

```Cake Migration Shell

PHP Fatal error: Cannot use 'object' as class name as it is reserved in /sites/gonzaga/lib/Cake/Core/Object.php on line 18
2018-04-03 08:31:38 Error: Fatal Error (64): Cannot use 'object' as class name as it is reserved in [/sites/gonzaga/lib/Cake/Core/Object.php, line 18]
2018-04-03 08:31:38 Error: [InternalErrorException] Internal Server Error
Stack Trace:

0 /sites/gonzaga/lib/Cake/Error/ErrorHandler.php(212): ErrorHandler::handleFatalError(64, 'Cannot use 'obj...', '/sites/gonzaga/...', 18)

1 /sites/gonzaga/app/Lib/GotsError.php(21): ErrorHandler::handleError(64, 'Cannot use 'obj...', '/sites/gonzaga/...', 18, Array)

2 /sites/gonzaga/lib/Cake/Core/App.php(970): GotsError::handleError(64, 'Cannot use 'obj...', '/sites/gonzaga/...', 18, Array)

3 /sites/gonzaga/lib/Cake/Core/App.php(943): App::_checkFatalError()

4 [internal function]: App::shutdown()

5 {main}```

This is a user error, please check your code.
The framework is fine.


This is not a help forum. The ticket tracker is reserved for possible
bugs and feature enhancements to the CakePHP framework. If you are
looking for help on how to implement a feature or to better understand
how to use the framework correctly, please visit one of the following:

The CakePHP Manual
The CakePHP online API
The CakePHP Forum
Stackoverflow

or the #cakephp channel on irc.freenode.net, where we will be more than
happy to help answer your questions.

Thanks!

I get the error about deprecated "each" function in DboSource for php 7.2 when setting order

Each has been deprecated in favour of foreach.
https://wiki.php.net/rfc/deprecations_php_7_2
https://secure.php.net/manual/en/migration72.php

I assume you can change the error reporting to not show deprecation warnings or better yet prep a PR for cakephp 2.x

I'm using PHP 7.2, cakephp 2.10.11.
I installed php-mcrypt but still failed "Cannot use 'object' as class name as it is reserved".
Can you support me, please ?

Interesting, I am having the same issue as @thuyhyvg stack trace to me looks like it is in the framework and not the specific code

PHP Fatal error:  Cannot use 'Object' as class name as it is reserved in /home/tom/Projects/sync/lib/Cake/Core/Object.php on line 30
PHP Stack trace:
PHP   1. {main}() /home/tom/Projects/sync/app/Console/cake.php:0
PHP   2. ShellDispatcher::run() /home/tom/Projects/sync/app/Console/cake.php:49
PHP   3. ShellDispatcher->dispatch() /home/tom/Projects/sync/lib/Cake/Console/ShellDispatcher.php:66
PHP   4. ShellDispatcher->_getShell() /home/tom/Projects/sync/lib/Cake/Console/ShellDispatcher.php:203
PHP   5. class_exists() /home/tom/Projects/sync/lib/Cake/Console/ShellDispatcher.php:252
PHP   6. spl_autoload_call() /home/tom/Projects/sync/lib/Cake/Console/ShellDispatcher.php:252
PHP   7. App::load() /home/tom/Projects/sync/lib/Cake/Console/ShellDispatcher.php:252
PHP   8. include() /home/tom/Projects/sync/lib/Cake/Core/App.php:547
PHP   9. spl_autoload_call() /home/tom/Projects/sync/app/Console/Command/AwsShell.php:7
PHP  10. App::load() /home/tom/Projects/sync/app/Console/Command/AwsShell.php:7
PHP  11. include() /home/tom/Projects/sync/lib/Cake/Core/App.php:547
PHP  12. spl_autoload_call() /home/tom/Projects/sync/app/Console/Command/AppShell.php:28
PHP  13. App::load() /home/tom/Projects/sync/app/Console/Command/AppShell.php:28
PHP  14. include() /home/tom/Projects/sync/lib/Cake/Core/App.php:547
PHP  15. spl_autoload_call() /home/tom/Projects/sync/lib/Cake/Console/Shell.php:31
PHP  16. App::load() /home/tom/Projects/sync/lib/Cake/Console/Shell.php:31
Fatal Error Error: Cannot use 'Object' as class name as it is reserved in [/home/tom/Projects/sync/lib/Cake/Core/Object.php, line 30]

Make sure nothing is using this class. No project file specifically.

Same as @Tom5om @thuyhyvg here -- PHP 7.2, cakephp 2.10.11, mcrypt via pecl and I still get 'Cannot use 'Object' as class name as it is reserved'

What is the stack trace? Reading above one, I think the app is using a legacy version of 2.x, as it is auto-loading Object on Shell.php:31. But there is no longer class Shell extends Object as of 2.8:
https://github.com/cakephp/cakephp/blob/31b13edf8a381cfe908890141c5387b3b45bc78f/lib/Cake/Console/Shell.php#L31
Legacy versions (CakePHP < 2.8)
https://github.com/cakephp/cakephp/blob/96c952180248c4a836afc8ba223b3ff8b4ef660e/lib/Cake/Console/Shell.php#L31

Fatal error: Cannot use 'Object' as class name as it is reserved in C:xampphtdocslmsvendoryiisoftyii2baseObject.php on line 77

i am using php 7.2.9
and yii 2.0

but still failed "Cannot use 'Object' as class name as it is reserved

please help me to solve this problem.

Since PHP 7.2 there are new forbidden class names of which one is object.

Upgrade yii to 2.0.13 or later.

https://www.yiiframework.com/news/149/yii-2-0-13-is-released#php-72-compatibility

It is the same issue CakePHP had with PHP7.2, but in this case it is problem with yii

Thanks Guys!
Cakephp 2.10.16 works on PHP 7.2.14

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nrother picture nrother  路  3Comments

Erwane picture Erwane  路  3Comments

berarma picture berarma  路  3Comments

caBBAlainB picture caBBAlainB  路  4Comments

lorenzo picture lorenzo  路  4Comments