• Archives

  • Categories

Aug 16

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 1.2.4.8284 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:

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…

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:

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. :)

Thanks jdbartlett! You saved me time. :)

Possibly related:

  1. How to do logging in CakePHP
  2. Why some people contribute to open source
  3. How to run XAMPP’s PHP CLI and CakePHP console
  4. How to load models from another CakePHP application

“CakePHP 1.2 and PHP 5.3 doesn’t play nice”
17 comments

  1. This happened to me yesterday when I upgraded to the latest version of XAMPP. Wasn’t pretty.

    Aug 16

  2. @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.

    Aug 17

  3. atomicguava

    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: http://uk2.php.net/manual/en/timezones.europe.php

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

    Aug 18

  4. atomicguava

    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.

    Aug 18

  5. Thanks atomicguava.

    To solve the “=&” problem, you can replace it with “= clone”. Correct me if I’m wrong here.

    Aug 19

  6. poornima

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

    Aug 22

  7. Hi poornima, that shouldn’t be occurring. Does it happen if you switch the debug mode to 1 or 0?

    Aug 23

  8. 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. :)

    Aug 29

  9. joseph

    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

    Aug 29

  10. Thanks jdbartlett, yours is a better idea. Doh! I didn’t notice that comment, joseph. I’ll add it up in the blog post.

    Aug 30

  11. Blake

    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

    Sep 17

  12. Blake

    I found my issue. I needed to set debug to 0.

    Sep 17

  13. 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.

    Amjith

    Sep 25

  14. 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.

    Sep 25

  15. h!ggs

    Put this bellow the defines in index.php:

    date_default_timezone_set(‘America/Chicago’);

    Change to your preferred TZ.

    Oct 25

  16. Jared

    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!

    Oct 27

  17. 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.

    Jan 21

Leave your comment.


WordPress powered and Django inspired.
Love and elephants come after.
RSS: Posts and comments.