PHP 5.3 is a full-size leap forward for PHP and brings of a lot of efficient features. Big leaps can also mean changes and potentially big splintering when it comes to backwards compatibility.
Here kevin from kevin.vanzonneveld.net sharing his experience on PHP 5.3 with you.
Et voila. An independent test platform that's able to reflect your code changes in real time.
This is the stuff that can get you fired.
So if you have these short tags, lets get rid of them. But how, there are so many!
Update #1 - As noted by Rune Kaagaard and Philip Olson in the comments, support for short tags is still a subject of discussion. Whether it will be turned off by default or supported in PHP 6 also depends on the package maintainers of each distribution (looks like Ubuntu is going for the strict approach).
Now, be sure to **go over the changes manually **with a tool like regexxer though. Cause if you're not careful code generators, highlighters & XML tools will break. Consider the following real life example:
**Update #2: **As Bernhard mentions in the comments, there is a much better way of removing shorttags from your PHP code.
The following example is still used in quite some code, but as of PHP 5.3 will generate "Deprecated" warnings.
Obviously - if you are the author of such lines - you should change your code. Now is the time.
But let's say you also use a framework (CakePHP in my case), and you are not the author. You need to wait for others to fix it (don't worry, PHP 5.3 releases of Cake are in the works, just not stable yet). But if you still want to run PHP 5.3 right now with a deprecated framework codebase you can't change: you can turn off these warnings by changing the level of error reporting.
Here's an example that still let's you see other debug messages like Notices (which is great during development), but just turns off the Deprecated warnings (which are useless if they concern the framework's code):
So put this wherever you currently set the error_reporting level.
For CakePHP 1.2, I found I had to hack my core in /cake/libs/configure.php at line #291 to get rid of the deprecated warnings.
Well, just uninstall them with apt (or rpm, or whatever) and reinstall them with pecl like this:
Here kevin from kevin.vanzonneveld.net sharing his experience on PHP 5.3 with you.
How to install PHP 5.3 on Ubuntu Jaunty
After reading this article you may want to install PHP 5.3 and If you have not tried PHP 5.3 earlier or you want to give it a go right now, here is the basic tips on the PHP 5.3· start on a virtual Ubuntu Jaunty instance
· Use the dotdeb.org repositories to install PHP 5.3 (Click on link to install PHP5.3)
· Point Apache's (or whatever) document root to your workstation's shared code directory.
Short Tags
When you do a fresh PHP 5.3 install on an Ubuntu Jaunty server, short tags, also known as:<?
New releases can have support off by default, hence just showing code as plaintext. Including db passwords.This is the stuff that can get you fired.
So if you have these short tags, lets get rid of them. But how, there are so many!
Update #1 - As noted by Rune Kaagaard and Philip Olson in the comments, support for short tags is still a subject of discussion. Whether it will be turned off by default or supported in PHP 6 also depends on the package maintainers of each distribution (looks like Ubuntu is going for the strict approach).
Regex to the rescue?
If you have a lot of short tags, the following regexes could help to convert them:replace: '<?='
with: '<?php echo '
replace: '<?(?!php|xml)'
with: '<?php'
The order of these replace actions is important.Now, be sure to **go over the changes manually **with a tool like regexxer though. Cause if you're not careful code generators, highlighters & XML tools will break. Consider the following real life example:
$CodeRow->replace('<?', '<?php', 'T_OPEN_TAG');'By our replace action, this would now read:
$CodeRow->replace('<?php', '<?php', 'T_OPEN_TAG');'Making that line completely useless and introducing a bug. So please, really go over the changes manually. Regexxer will make that job less painful already.
**Update #2: **As Bernhard mentions in the comments, there is a much better way of removing shorttags from your PHP code.
After the changes
Test your code thoroughly before you commit.PHP Deprecated warnings
Some 'old' syntax still works but generates "Deprecated" warnings. These are telling you to change your code before it's too late: future versions of PHP will no longer support it. At all.The following example is still used in quite some code, but as of PHP 5.3 will generate "Deprecated" warnings.
$log = & new Logger('file', '/var/log/app.log');They want you to get rid of the '&'.
Obviously - if you are the author of such lines - you should change your code. Now is the time.
But let's say you also use a framework (CakePHP in my case), and you are not the author. You need to wait for others to fix it (don't worry, PHP 5.3 releases of Cake are in the works, just not stable yet). But if you still want to run PHP 5.3 right now with a deprecated framework codebase you can't change: you can turn off these warnings by changing the level of error reporting.
Here's an example that still let's you see other debug messages like Notices (which is great during development), but just turns off the Deprecated warnings (which are useless if they concern the framework's code):
error_reporting(E_ALL & ~ E_DEPRECATED);.. basically saying: Show all warnings except deprecated.
So put this wherever you currently set the error_reporting level.
For CakePHP 1.2, I found I had to hack my core in /cake/libs/configure.php at line #291 to get rid of the deprecated warnings.
MySQL
In Ubuntu (thanks Philip Olson), PHP 5.3 uses a native MySQL driver (mysqlnd) and it enforces strong passwords. We still had some legacy 16bit MySQL passwords and so MySQL guru Erwin Bleeker upgraded them in order for mysql_connect to work. Good thing I suppose ;)Extensions
I had some extensions like php5-xdebug, php5-xcache, php5-memcache that I previously installed with APT package management, but now gave version conflicts with my custom dotdeb.org packages.Well, just uninstall them with apt (or rpm, or whatever) and reinstall them with pecl like this:
pecl install -f memcache
So that the extensions are rebuild for your current PHP version and the conflicts are resolved. Make sure your php.ini files point to the right .so files though.
0 comments:
Post a Comment