|
If you are running Joomla 1.0.15 and your provider upgrades
from PHP 5.2 to 5.3 you will be faced with a lot of error messages of the type:
Assigning the return
value of new by reference is deprecated
Function eregi() is deprecated
Function eregi_replace() is deprecated
Function split() is deprecated
Deprecated: Function set_magic_quotes_runtime() is deprecated
To fix this situation if you are going to continue run Joomla
1.0.15 on PHP 5.3 you have several choices: Firstly, find a friendly host that
will continue to run PHP 5.2 for you. This is possible but let us be honest this
is only a temporary solution as PHP 5.2 will eventually be shelved by everyone
and when 5.3 is rolled out everywhere, you will be left out in the cold. It is
only a matter of time. However, if you do need such a friendly host then contact
me and I'll provide the details.
Secondly,
upgrade your Joomla 1.0.15 website, extensions and applications to the latest
version of Joomla 2.5. This is a fine and laudable idea but in reality it is
rather a lot of work, probably several days and of course, an upgrade - it
isn't. It is a straight site rebuild from scratch which may end up looking just
the same as the old site but for a lot of work and a lot of cash. To perform a
Joomla site migration you have to migrate to 1.5 first and then of course you
have to migrate to 1.6/7 then to Joomla 2.5 and again to 3.0 when it comes out,
bearing in mind the current frequency of Joomla releases means that you could be
rebuilding your site every year to eighteen months...and this does not even take
into account all the 3rd party application data you will also need to migrate.
Thirdly, you could migrate to Joostina 1.3, Joostina is
Joomla 1.0.15 on steroids and is fully compatible with PHP 5.3. The upgrade from
Joomla 1.0.15 to Joostina 1.2 was very simple, you just needed to copy the PHP
code over the old joomla code and then you had a fully Joomla 1.0 compatible
site that ran all your Joomla extensions. All you needed to do was to change the
language files from Russian to English.
The upgrade from Joostina 1.2 to 1.3 (to obtain PHP 5.3
compatibility) is merely an upgrade and not a whole migration as is the
'upgrade' from joomla 1.0 to 1.5. Apart from copying the code the only
significant changes being a few extra columns in certain tables. The good thing
about Joostina 1.3 is that it is fully PHP 5.3 compatible. As long as your
joomla extensions are all PHP 5.3 compatible then you are laughing!
The only major obstacle is that Joostina is still a Russian
CMS and the English translations are lagging behind. I can now easily install an
English version of Joostina 1.2 and with the English language translation files
in place you could easily use the backend, seeing only a very few remaining
untranslated items. Joostina 1.3 is fully PHP 5.3 compatible but as yet it seems
that no-one has been able to find the time to convert the backend language files
to English. Give me time though and I intend to do it so this route will finally
be a realistic option. Click here to view a site running Joostina 1.2 on PHP 5.2
http://www.newventureproducts.co.uk (PHP 5.3 site build in progress - link
coming soon).
So, that brings us to the main choice, you can simply make changes to your
Joomla 1.0 installation to make it PHP 5.3 compatible. This is probably the
easiest option and it will take approximately a day.
Option no.4 - Make Joomla 1.0 installation
PHP5.3 compatible - How to actually do it?
You will need a good ftp tool such as
WinSCP to transfer the files to your PC where you will be making the
changes, a good search and replace tool such as
Ecobyte's "Replace Text 2.2" , a good search tool such as 'baregrep
' and a good code editor such as 'context
'. You will be searching for occurrences of deprecated PHP 5.2 functions such as
eregi, eregi_replace, ereg, &new
and split and you will be amending
them so that they stop generating any errors when your PHP is upgraded to 5.3.
Baregrep can make it very easy to see where these functions occur in the Joomla
code, simply search all *.PHP files for the deprecated functions. When you are
confident about making the changes, Ecobyte's search and replace tool will make
it very easy to actually make the changes to the code without any accidentally
making any mistakes.
The first task is to transfer the files down to your PC so you can make the
changes locally. Either take a backup, transfer the backup down and restore it
locally or simply transfer all the site files down manually. I transferred not
only Joomla but all my 3rd party components, modules and mambots, the lot, as I
was prepared to make changes to them all at the same time.
Replacing ereg
When you have a local copy of the site ready for change, use
baregrep and search for 'ereg' in all PHP files. All occurrences of any function
starting with 'ereg' must be changed to '@ereg', this will suppress any error
messages generated when PHP is using these functions. You can't do the changes
manually as there may be many occurrences of the text to change, you'll need a
bulk text changer like Ecobyte's "Replace Text 2.2" or a similar tool to make
the changes. Ecobyte's "Replace Text 2.2" isn't the easiest tool to use but get
the hang of the tool as it does the job well.
look for: ereg
(note the preceding space) and replace with:
@ereg
complete with preceding space.
look
for: (ereg
and replace with: (@ereg
look
for: !ereg
and replace with:
!@ereg
-oOo-
Things to watch out for:
Take care not to replace any other occurrences of this
text string in help messages or in text/code elsewhere. For example in the Dutch
translation of some components the word
Geregistreerd is used regularly and it contains 'ereg'. Also some daft
programmers use the text 'ereg' in their variables, joomlaXplorer does this
using a variable $ereg.
Basically, you will need to review all your changes to ensure
that only changes to deprecated code are made.
You should watch out for the geshi library files
\libraries\geshi\php-brief.php
and \libraries\geshi\php.php
- don't make any changes in these two files as it is simply referring to the
utilities and not calling them.
Purists
will state that suppressing the errors is not the right thing to do and instead
you should be replacing the 'ereg' functions with PHP 5.3 'preg' functions. This
is the 'ideal' thing to do in an ideal world but in reality the number of
changes you would be making and the amount of testing you would have to do makes
this a little impractical. Be aware that these 'deprecated' errors are just
warnings in any case, their job is to make the site owner aware that these 5.2
functions will one day be removed from future versions of PHP. The good news is
that regardless of the messages, they work perfectly well in PHP 5.3 and 5.4, so
for the medium term, usage of these functions is secure for your Joomla 1.0
site. We are not talking months but several years here regarding the
availability of PHP 5.3 alone. Web hosts first started running PHP 5.2 in 2007
and it is stll here in late 2012. PHP 5.3 arrived in mid-2009 and will be
available until 2015-2016.
Replacing split
The second task is to search for use of the function 'split' and replace it with
the new PHP 5.3 function 'explode'. It is a straight like-for-like swap, easy
to do. Be careful of replacing every occurrence of split as this is also a
commonly used word and is likely to be used elsewhere in 3rd party code,
possibly as a variable, just look for all uses of the split text and be prepared
to exclude files that make use of the word split in other ways.
look for:
split (
(note the preceding and subsequent spaces) and replace with
explode(
complete with preceding and following spaces.
split(
(note the preceding space) and replace with
explode(
complete with preceding space.
.split(
and replace with .explode(
Note that the word split is used in other functions such as
preg_split so don't just do a general search and replace on the word 'split',
ensure that you replace exactly as specified above with a preceding space and
full stop.
Replacing &new / & new
The third and final task you will need to perform is to look
for all occurrences of '& new' and '&new' statements and replace them simply
with 'new'. Once again, be careful and selective where you make changes as
'&new' may also appear as part of a hard-coded URL especially in 3rd party
components that build URLs such as virtuemart.
Removing set_magic_quotes_runtime errors
The magic quotes runtime was previously used to ensure that any functions
that returned data from any sort of external source including databases and text
files would have quotes escaped with a backslash, it was deprecated in PHP 5.3.
As a result the following error will occur many times when you have Joomla
cacheing switched ON:
Deprecated: Function set_magic_quotes_runtime()
is deprecated in Cache/Lite.php on line 524
Some changes need to be made to this file
/includes/Cache/Lite.php
All occurrences of the set_magic_quotes_runtime
function need to be replaced by a conditional if statement.
for example:
//set_magic_quotes_runtime(0); - this the old line
// Check if magic_quotes_runtime is active
if(get_magic_quotes_runtime())
{
// Deactivate
set_magic_quotes_runtime(0);
}
The function occurs three times in various forms within the file, simply
change each occurrence and add a wrapper to each. When you turn cacheing back on
the error will no longer occur.
The icon that creates a PDF version of the page content on all articles uses
the magic quotes function, you will need to modify
/public_html/libraries/tcpdf/tcpdf.php
in the same way as you modified lite.php above.
-oOo-
com_contact vcard.class.php error
When you click on the contact page of your site if you are using the Joomla
1.0 contact component, the following error may occur.
Fatal error: Cannot redeclare
quoted_printable_encode() in includes/vcard.class.php on line 74
In vcard.class.php at line 36 you will find the function 'quoted_printable_encode'.
This function is declared twice. To avoid the error add some code to checking if
the function already exists. Add the if
statement and subsequent closing curly bracket }.
if(!function_exists('quoted_printable_encode')) {
function quoted_printable_encode($input, $line_max=76) {
.
.
.
}
}
-oOo-
That's it, that is the changes made. So how do we test? Many professional
hosts can turn on PHP5.3 selectively, so if you are running WHM and CPANEL then
each of your domains can simply be toggled between PHP 5.2 and 5.3. It might be
wise to build a duplicate site and switch that to 5.3 as a trial
You could simply inform your users and switch your target site to PHP 5.3 -
but that might be just asking for trouble. I suggest you build a duplicate,
switch it to PHP 5.3, make the changes, at first it will still generate hundreds
of error messages of the type:
Assigning the return
value of new by reference is deprecated
Function eregi() is deprecated
Function eregi_replace() is deprecated
Function split() is deprecated
Deprecated: Function set_magic_quotes_runtime() is deprecated
But as you selectively apply your code changes to the site you can watch as
the errors disappear... When the site is complete it will be ready to go live.
If you have made the changes locally you should then start to
migrate them back to the live site using your FTP tool. I recommend that you
copy chunks of the code up, folder by folder. Perhaps, first the administrator
sections, modules, templates &c.What I dois to rename the old modules folder to
modules.1 and then copy the new modules folder across. This means I have the old
unchanged folder to hand just in case I need to restore a file or two.
Then check the backend works as you copy each folder in turn.
Any errors introduced will be easier to diagnose if done bit by bit. Check the
standard Joomla back end and then the components, modules and mambots. Check the
errors as they occur and fix them as they crop up. Most will be caused by
accidental or mistaken replacements. Remember, you have the backups and can
restore any file you need.
Then copy the include folder, front end mambots, modules and
components folders, taking care to test as you copy. In this way it should be
possible to make and migrate all the changes within the span of one day's hard
work, even including time spent diagnosing mistakes made in error, in the code.
-oOo-
It will take a while but the end result will be a Joomla 1.0.15 site that is
fully functional in PHP 5.3, a site that will be able to run for three/four more
years, this will give you time to replace those ereg functions with the correct
'preg' functions so that the site will be fully compatible with even later
versions of PHP beyond 6.0.
Bear in mind that there is a real concrete benefit from
running Joomla 1.0.15 in PHP 5.3 - the site will run significantly faster as
PHP5.3 is definitely quicker than 5.2. It will run faster than an equivalent
Joomla 1.5 site and that one benefit alone benefit cannot be dismissed.
Lastly, a kind soul called Micheas Herman has created an unofficial patch of
Joomla 1.0 to take it to 1.0.16. What he has done is to replace a lot of the
deprecated functions with updated code that is now compatible with PHP 5.3.
However, the changes are incomplete and as a result there are still occurrences
of deprecated code in the code base and so errors will occur. I estimate that
the job is approx. 70% complete and I am guessing that Michaes simply made
changes to prevent any errors that were occurring on his site. These may well
correct the majority of errors in the majority of sites - so the patch may well
be suitable for you. However I consider it a work in progress but a good base
from which to continue to make the changes. I making the remainder of the
changes myself and will offer an unoffical 1.0.17 patch to download when it is
ready.
Michaes 1.0.16 patch is here and my Joomla 1.0.17 patch
will be here when it is ready - it is currently untried and untested but the
changes have been made to the code.
-oOo-
To show you that running a Joomla 1.0.15 site on PHP 5.3 is
possible, here is an example of a modified Joomla 1.0.15 site running Virtuemart
1.0.15 on PHP5.3 -
carstuffdirect.co.uk. This site has had all the deprecated ereg functions
replaced by preg_match syle functions. The site is an un-cached and un-optimised
site that runs efficiently and definitely faster than a comparative Joomla 1.5
site. So, if you want your Joomla 1.0.15 site to be transplanted deeper into the
21st century without having to incur all the work to migrate and rebuild a new
site from scratch then this is a workable alternative. None of this work is
beyond a Joomla specialist and you could possibly do it yourself if you are an
Joomla enthusiast - with some technical competence, some confidence and the free
tools listed above.
If you want someone else to carry out the work for you then it could be done
for a mere day's pay ...
contact me here:
|