PHP 7.2 Support


#1

Hi, I was wondering when PHP 7.2 will be officially supported by Cake. I have the latest Cake version (3.5.9) and tried it with PHP 7.2.0 yesterday. The site seems to work fine (after I changed some config/app.php settings), but during unit testing (with PHPUnit 6.5.5) I’m seeing a ton of new PHP warnings. The only change I made was upgrading from PHP 7.1.12 to 7.2.0.

The warnings are new in 7.2 - I even saw them in PHP’s source code. They changed the way sessions are handled. Cake has some sessions code to help with this change but it doesn’t seem sufficient yet. Some people are calling the new warnings a PHP bug. So I was just wondering if the Cake team had plans or a timeline to address this. I want to use the new security features in 7.2 but I’d prefer to wait until all the warnings/notices disappear.

Here’s an example of the warnings:

session_set_save_handler(): Cannot change save handler when headers already sent

The warnings mostly occur during unit testing when a route is accessed. Technically, the warning is correct since PHPUnit has already output to the console when the route is accessed and the session is attempting to re-initialize.

The change I had to make to my app.php file was for the Sessions config. I had to copy all of the database defaults but leave the “session.save_handler” entry missing so that Cake wouldn’t try to set it to “user”, which is now an invalid option.


#2

The latest CakePHP 3.5.x release already supports PHP 7.2. Our testsuite is run on PHP 7.2 without any failures https://github.com/cakephp/cakephp/blob/master/.travis.yml#L7

Maybe your app config was outdated, please refer to the latest app skeleton. Your app tests might also have to be updated to account for sesssion config related changes in PHP 7.2.


#3

This sounds to me like a warning is emitted.
Read your error.log and see what causes the headers to be sent (some kind of output).
That will be your issue.


#4

Thanks for the advice guys. I looked into your suggestions, and the problem persists. The good news is that this problem is repeatable. I installed a fresh copy of Cake and got the warnings by changing the Session config to use database sessions.

Steps to reproduce:

  1. Install a new copy of CakePHP
  2. Edit the Session section of config/app.php to include this from the docs:
'Session' => [
    'handler' => [
        'engine' => 'DatabaseSession',
        'model' => 'CustomSessions'
    ]
]
  1. Run “phpunit” using PHP 7.2.0 at the command line
  2. You will hopefully see the same PHP warnings that I do:
    Warning (2): session_set_save_handler(): Cannot change save handler when headers already sent in […/my_app_name/vendor/cakephp/cakephp/src/Network/Session.php, line 220]

I don’t see those warnings if I use the “php” Session defaults, so something about the database sessions seems to make the difference.

Adding ‘defaults’ => ‘database’ to the config doesn’t make any difference.

On a related note, digging into the Cake source in Session.php, it looks like database sessions set ‘session.save_handler’ => ‘user’, which is no longer a valid PHP session setting.

Btw, here’s a link to the bug report on this topic: https://bugs.php.net/bug.php?id=75628

Can somebody try the steps above and see what happens?


#5

Anybody else tried DB sessions with PHP 7.2?