Cakephp4 debug before write session

  1. create clean project

  2. edit PagesController.php line 48-49

     Argument 1 passed to Cake\Http\Session::_overwrite() must be of the type array, null given, called in /work/cakePHP4bug/vendor/cakephp/cakephp/src/Http/Session.php on line 495

The write function wants to know the key and value that you’re trying to write. You’re only providing a key.

cakephp: 4.0.8
ref: vendor/cakephp/cakephp/src/Http/Session.php line 480
public function write($name, $value = null): void

this case no problem, please read my error message

Looking at the implementation of Session.php, the first parameter to the _overwrite function (as specified by your error message) is $_SESSION. If that’s not an array, then I guess the session hasn’t been initialized at all in your application before this point?

yes, this case have return false before session_start at
public function start()

if (ini_get(‘session.use_cookies’) && headers_sent()) {
return false;

is normal?

I wouldn’t think that’s normal. Do you have something generating output, maybe some debug thing, before this is called? Is the ini file set up right? Are permissions right on the file where sessions are saved? Or if you’re using database sessions, have you added the table?

i compare between cakephp3 and cakephp4 on the same system and environment.
maybe cakephp4 very strict?


Have you looked at the migration notes for v4? There are a lot of things that have changed, this might be one of them.