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?


#6

I tried this again with the newest CakePHP 3.5.11, which has some fixes for this problem, but I am still getting the same PHP warnings.

Can somebody else try the steps above to replicate the problem?


#7

Hi folks,

I also get the following error with php 7.2.7 from cakephp 3.6.7 with phpunit 7.2.6 on mac os Sierra 10.13.3. Anybody get this error as well on mac ? (I have no errors with php 7.x, on mac and windows with cake 3.5.x and 3.6.x but phpunit 6.2.4)

And according to this post, BaseTestListener has been removed in phpunit 7.

PHP Fatal error:  Class 'PHPUnit\Framework\BaseTestListener' not found in /Users/zzz/Sites/yyy/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php on line 28

Fatal error: Class 'PHPUnit\Framework\BaseTestListener' not found in /Users/xxx/Sites/eva/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php on line 28
Fatal Error: Class 'PHPUnit\Framework\BaseTestListener' not found in [/Users/zzz/Sites/yyy/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php, line 28]

#8

@Speudyland CakePHP 3.x doesn’t support PHPUnit 7 yet, afaik.


#9

Yes that’s what I suppose, it’s not working yet but soon enough it’s gonna run :wink: Meawhile PHPUnit 6.x works fine with cake 3.x :sunglasses:


#10

Hi there,

I am having the same warning,
at this line
#294 session_set_save_handler($handler, false); //Session.php

I’m using CakePHP 3.6.10 with Redis Session and PHP 7.2.7

Thanks,


#11

What is in your app.php config file for Session? I think I had to modify mine to work after updating to PHP 7.2 while using DB sessions. Here’s what I use with CakePHP 3.6:

'Session' => [
    //'defaults' => 'php',
    'defaults' => 'database', // changed this to use the DB
    'timeout' => 60,
    //'cookieTimeout' => 0,
    'handler' => [
        'engine' => 'DatabaseSession',
        'model'  => 'UserSessions'  // DB table name is user_sessions
    ],
    'cookie' => 'sessionId',  // custom cookie name
    'ini' => [
        // Delete old sessions every 50th page view
        'session.gc_probability' => 1,
        'session.gc_divisor'     => 50,
    ]
],

#12

Has this issue been resolved yet? I’m running into a similar problem while running cakephp version 3.6 and using phpunit 7.5.1.

I’m unable to get phpunit to work and run with my current projects in cakephp. Are there any recommendation for next steps or pointers to the solution?


#13

I have the same problem with CakePHP 3.4.14 through 3.7.0 on PHP 7.2.13 on Debian stretch (PHP 7.2.13 installed from sury repo.)
I want to store sessions on Redis, my app.config is as follows:
'Session' => [ //'defaults' => 'php', 'handler' => [ 'config' => 'session' ], 'defaults' => 'cache', 'ini' => [ // Invalidate the cookie after 30 minutes without visiting // any page on the site. 'session.cookie_lifetime' => 1209600 ], 'timeout' => 20160 ],
the issue goes away by commenting the following line in Session.php file but it’s not the right solution:
'cache' => [ 'cookie' => 'CAKEPHP', 'ini' => [ 'session.use_trans_sid' => 0, 'session.use_cookies' => 1, #'session.save_handler' => 'user', ], 'handler' => [ 'engine' => 'CacheSession', 'config' => 'default' ] ],
Anyone has any answers whether an update can solve this or I should downgrade to PHP7.1


#14

The session.save_handler key gets unset for PHP > 7.2.0, so I wonder why you guys are still having problem.