2

I have a PHP application which has been developed with CakePHP 2.4.6 on Ubuntu Virtual Machine with PHP 5.3.10-1ubuntu3.11 installed on it (with Apache2). My problem is that I wanted to deploy it to the real server, which has PHP 5.4.16 and I get the following errors:

Warning (2): Illegal string offset 'session.cookie_lifetime' [CORE/Cake/Model/Datasource/CakeSession.php, line 482]
Warning (2): Illegal string offset 'session.name' [CORE/Cake/Model/Datasource/CakeSession.php, line 485]
Warning (2): Illegal string offset 'session.gc_maxlifetime' [CORE/Cake/Model/Datasource/CakeSession.php, line 491]
Warning (2): Illegal string offset 'session.cookie_httponly' [CORE/Cake/Model/Datasource/CakeSession.php, line 494]
Warning (2): Illegal string offset 'session.cookie_lifetime' [CORE/Cake/Model/Datasource/CakeSession.php, line 482]
Warning (2): Illegal string offset 'session.name' [CORE/Cake/Model/Datasource/CakeSession.php, line 485]
Warning (2): Illegal string offset 'session.gc_maxlifetime' [CORE/Cake/Model/Datasource/CakeSession.php, line 491]
Warning (2): Illegal string offset 'session.cookie_httponly' [CORE/Cake/Model/Datasource/CakeSession.php, line 494]
Warning (2): Illegal string offset 'session.cookie_lifetime' [CORE/Cake/Model/Datasource/CakeSession.php, line 482]
Warning (2): Illegal string offset 'session.name' [CORE/Cake/Model/Datasource/CakeSession.php, line 485]
Warning (2): Illegal string offset 'session.gc_maxlifetime' [CORE/Cake/Model/Datasource/CakeSession.php, line 491]
Warning (2): Illegal string offset 'session.cookie_httponly' [CORE/Cake/Model/Datasource/CakeSession.php, line 494]
Warning (2): Illegal string offset 'session.cookie_lifetime' [CORE/Cake/Model/Datasource/CakeSession.php, line 482]
Warning (2): Illegal string offset 'session.name' [CORE/Cake/Model/Datasource/CakeSession.php, line 485]
Warning (2): Illegal string offset 'session.gc_maxlifetime' [CORE/Cake/Model/Datasource/CakeSession.php, line 491]
Warning (2): Illegal string offset 'session.cookie_httponly' [CORE/Cake/Model/Datasource/CakeSession.php, line 494]

I have read about this error, that (if I'm not mistaken) it means you want to use a string as an array, but it has something with the CakePHP's core and not with my PHP application.

It gives these errors (warnings) to all of my pages, and the content is not loaded, so I really only see these messages without any css or html layout.

It was running properly on my virtual machine, so I can just assume that it has to do something with the newer version of PHP installed on the server.

I have also tried to use a newer version of CakePHP, version 2.5.1, but it has also resulted in these kind of errors.

Update 1: Here is the relevant PHP code snippet from the CakeSession.php file:

if (!isset($sessionConfig['ini']['session.cookie_lifetime'])) {
    $sessionConfig['ini']['session.cookie_lifetime'] = $sessionConfig['cookieTimeout'] * 60;
}
if (!isset($sessionConfig['ini']['session.name'])) {
    $sessionConfig['ini']['session.name'] = $sessionConfig['cookie'];
}

And these are the variables, the DebugKit shows:

$sessionConfig = array(
    'cookie' => 'CAKEPHP',
    'timeout' => '240',
    'ini' => 'C / 14400 CAKEPHP 14400 1',
    'defaults' => 'php',
    'cookieTimeout' => '240'
)
$defaults = array(
    'cookie' => 'CAKEPHP',
    'timeout' => (int) 240,
    'ini' => array(
            'session.use_trans_sid' => (int) 0,
            'session.cookie_path' => '/'
    )
)

Update 2: I have tried to put a clean CakePHP from Git (with the app folder also) and it works. So it seems to be there are some problems with my application... But where should I look?

Any suggestions? Thanks in advance.

zdtorok
  • 594
  • 1
  • 7
  • 21
  • 1
    The `ini` key is a string, so that's what the error is most likely triggered for. Check the session configuration in your `core.php` config file, in case the `ini` key contains a proper array, try to trace down where things go wrong by dumping `Configure::read('Session')` here and there in the request flow until you can pinpoint where the data changes to a string. Maybe start in `CakeSession::_configureSession()` to rule out the `Hash::merge()` call. – ndm Jun 03 '14 at 17:48
  • Thank you for your comment. I have taken a look on the function you have mentioned and I have realized maybe something has gone wrong at the Configuration part, so I could find the source of my error what - if you're interested - you can read in my answer below. – zdtorok Jun 04 '14 at 08:51

1 Answers1

0

I have found the source of the problem. I have created a configuration page where I read my configuration details from a j_config.php file. I have also created the Session variable to be modifiable on this configuration page but I didn't realize that the Configure::read('Session.ini') is an array and not a string and I have just put this into an input field and it has been automatically cast to string. So in brief, because of this array to string cast I have had in my Session:

array (
    'cookie' => 'CAKEPHP',
    'timeout' => 240,
    'ini' => 'C / 14400 CAKEPHP 14400 1',
    'defaults' => 'php',
    'cookieTimeout' => 240,
),

instead of:

array (
    'cookie' => 'CAKEPHP',
    'timeout' => 240,
    'ini' =>
    array (
      'session.use_trans_sid' => 0,
      'session.cookie_path' => '/',
      'session.cookie_lifetime' => 14400,
      'session.name' => 'CAKEPHP',
      'session.gc_maxlifetime' => 14400,
      'session.cookie_httponly' => 1,
    ),
    'defaults' => 'php',
    'cookieTimeout' => 240,
),

And as it's working in PHP 5.3, it is not going to work in PHP 5.4 because as I have cast my array into a string, I should cast it back to an array (or to be more precise: use my previously created string from the array as an array) which gives this error/warning in PHP 5.4.

zdtorok
  • 594
  • 1
  • 7
  • 21