CakePHP 1.2 and PHP 5.3 doesn’t play nice

I just upgraded all the software only to discover PHP got upgraded to 5.3. That’s fast, PHP 5.3 isn’t out too long ago and it’s in the Macosforge repository. Even the CakePHP update released on August 9 did not include PHP 5.3 compatibility.

Perhaps it’s time to update the CakePHP requirements and be indicative of the lack of support for PHP 5.3.

Now the library is throwing deprecated notices all around “Assigning the return value of new by reference is deprecated in…”. Also there is a PHP warning:

[code lang=”php”]PHP Warning: strtotime(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Singapore’ for ‘SGT/8.0/no DST’ instead in…[/code]

To stop the deprecated notices, I had to modify Cake’s core, not something I like to do.

I added the line “error_reporting (E_ALL & ~E_DEPRECATED);” at the top of /cake/libs/object.php. I also updated /cake/libs/configure.php by changing “error_reporting(E_ALL);” to “error_reporting (E_ALL & ~E_DEPRECATED);”.


This doesn’t solve the problem exactly, it just suppresses the deprecation notices so I can continue working. For a PHP 5.3 compatible CakePHP, you’ll need to use CakePHP 1.3 which currently isn’t stable. I’ll definitely be trying it soon but in the meantime I’ll just have to suppress error reporting.

Update: jdbartlett commented on a better way:

[code lang=”php”]if (defined(“E_DEPRECATED”)) error_reporting(E_ALL ^ E_DEPRECATED);[/code]

If you’re not doing any debugging, you can add the above code to the top of /app/webroot/index.php and suppress the error messages without editing the core. πŸ™‚

Thanks jdbartlett! You saved me time. πŸ™‚

18 thoughts on “CakePHP 1.2 and PHP 5.3 doesn’t play nice”

  1. @Ivan I upgraded it in OS X and got a bunch of errors. Scared me for a while. I almost wanted to downgrade as I was afraid it would affect my ongoing projects.

  2. Those strtotime warnings can be suppressed by uncommenting and completing the ‘date.timezone’ section of PHP.ini under the Module Settings section.

    For example: date.timezone = Europe/London

    For a complete list of timezones, please go to:

    Hope this helps someone else as it scared the life out of me following the upgrade!

  3. Since following your error_reporting tip and setting the timezone correctly in php.ini, CakePHP 1.2 and PHP 5.3 seem to play fairly nicely – although now I’ve got to go through my code and remove all those pesky ‘=&’ pass by references.

    Seems very snappy – especially with the new MySQL native driver.

  4. i have some problem in cackephp
    when i login i get this message SELECT, User.username FROM users AS User WHERE username = ‘newuser’ AND password = ‘098f6bcd4621d373cade4e832627b4f6’ LIMIT 1 how to avoid it

  5. I’m working with PHP 5.3 locally, but deploying to a server using PHP 5.2. E_DEPRECATED wasn’t added as a constant until PHP 5.3, so I’m using this logic to hide the “deprecated” error messages locally without having older versions of PHP look for a constant that doesn’t exist:

    if (defined(‘E_DEPRECATED’)) error_reporting(E_ALL ^ E_DEPRECATED);

    If you’re not doing any debugging, you can add the above code to the top of /app/webroot/index.php and suppress the error messages without editing the core. πŸ™‚

  6. jdbartlett,

    thanks, i wish your comment was mentioned in the blog itself, i edited the core and than read the comments..

    depending on the purpose of their project this ‘fix’ should mention the options of where they can edit to suppress the error logs..

    thanks again

  7. I have followed jdbartlett’s comments, but my timezone won’t change. I have restarted MAMP multiple times. I have tried to set date_default_timezone_set(‘America/Chicago’); in /app/webroot/index.php, but for some reason MAMP won’t acknowledge any timezone changes that I make. I find it odd that MAMP’s default php.ini file doesn’t have a commented out “;date.timezone =” line.

    Anyone else have this issue?

    I am using the following line in php.ini
    date.timezone = America/Chicago

  8. Hi,

    I still cant fix the issue with any of your comments. some one says they have fixed with “jdbartlett ” comment. But still issue exists. i have updated my cake folder with 1.3 version. This issue happened when i installed WAMP latest version πŸ™

    Thanks for all.


  9. Amjith Ps: The latest stable 1.2.5 resolves this issue partially. The CakePHP 1.2.5 shell still has the deprecate problem though. If you have upgraded to CakePHP 1.3, you shouldn’t be encountering the above problem already. It appears to have been fixed there.

  10. For those on Snow Leopard (Mac OS X 10.6), PHP was upgraded to version 5.3, but there is no php.ini file by default. You can define your server timezone in php.ini to solve the problem described in this post.

    First, copy the /private/etc/php.ini.default file to /private/etc/php.ini. Then uncomment the date.timezone line of your new php.ini file (by removing the leading semicolon) and add the correct timezone to the end of the line so the line now looks like this:

    date.timezone = “America/Denver”

    Save the file, and remember to restart your web server to use this updated php.ini file. Hope this helps!

  11. Hello,

    I’m using the latest stable 1.2.x and in the file app/config.core.php, simply uncomment this line: date_default_timezone_set(‘UTC’);

    The warning messages will disappear.

  12. CakePHP 1.2 and PHP 5.3 seem to perform pretty perfectly – although now and CakePHP allows you to set up a combination of controllers, models, and views and release them as a packaged application plugin that others can use in their CakePHP applications.

Leave a Reply

Your email address will not be published. Required fields are marked *