Running Joomla 1.0 on PHP 5.3 without errors
Of course ideally nobody should be using Joomla 1.0 any more as it is no longer supported and might contain security vulnerabilites. In reality, sometimes you just have to let a 1.0 site linger for a while until you get time to upgrade. But if your host upgrades to PHP 5.3, you can find your site breaks completely.
In particular, you can find that the content area is blank, the contact us page is completely blank, and lots of error messages appearing on screen warning about PHP functions that are 'deprecated'. Whilst I was able to find fixes for some of these errors on various different sites, nobody seems to have a complete patch for getting Joomla 1.0 running on PHP 5.3. So I thought I'd better write one.
I applied the fix for the content area and contact pages being blank, then searched through the entire code looking for all the function calls to eregi, eregi_replace, split, and assigning new by reference (=& new). These seem to be the main culprits for generating 'deprecated' errors which may fill up the screen or cause your error log to grow enormous. There might be others, but I haven't come across them yet. I replaced these functions with PHP 5.3 equivalent code. To apply the patch, download the following file, unzip it on your computer, and upload to your Joomla 1.0.15 site (use entirely at your own risk, and make sure you back up your site first, just in case!):
http://www.netshinesoftware.com/downloads/joomla_1_0_15_for_php_5_3_patch.zip
This is of course released under the GPLv2 license.
The patch only includes core Joomla files. You might have 3rd party extensions that also produce errors. In this case, here is a brief guide on how to fix eregi, eregi_replace, split, and =& new (again, use this information entirely at your own risk):
In the error message (either on screen or in your error log) it usually tells you which file and line number is causing a problem.
Assigning the return value of new by reference is deprecated
If you get this error, just look for "=& new" and remove the ampersand (so it just says "= new").
Function eregi() is deprecated
You can replace eregi with preg_match, however you have to add a delimiter and a directive. Typically you use a forward slash as the delimter, but if the contents of the pattern in the first parameter contains a forward slash you will have to choose a different character (eg. a hash # or a pipe | are common alternatives). At the end of the string, you repeat the delimter, followed by the letter 'i' (meaning case insensitive). For example, change this:
eregi('pattern', $string)
to this:
preg_match('/pattern/i', $string)
or if the pattern contains a forward slash already, you could use this instead:
preg_match('|pattern|i', $string)
Function eregi_replace() is deprecated
This is dealt with in the same way as eregi, above, but instead of using preg_match, you use preg_replace.
Function split() is deprecated
In most cases you can simply replace split with explode. If the first parameter is a regular expression, you have to use preg_split instead.
Comments
Tanks for sharing this outstanding work.
It works great!
However, I found your fix and it worked perfectly (though I did have to upload each file manually for some reason).
Many, many thanks!
Thank you for sharing !
if (eregi($regexSuffix.'$', $imptrim)) {
No Matter what i try:
if (preg_match($regexSuffix.'/$/i', $imptrim)) {
if (preg_match($regexSuffix.'/$/', $imptrim)) {
if (preg_match($regexSuffix.'/^$/i', $imptrim)) {
and so on, i always get:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in ....
Can someone help me with that?
if (preg_match('/' . $regexSuffix . '$/i', $imptrim)) {
Depending on the contents of $regexSuffix and the purpose of the dollar sign at the end, you might need to add a backslash before the dollar sign, eg:
if (preg_match('/' . $regexSuffix . '\$/i', $imptrim)) {
I had to solve this joomla 1.0.15/php5-problem on some sites and this was easy, fast, stable with your patch!
The patch worked fine and i had to replace 1 split to explode.
Good job and thank you.