This is an attempt to share a Drupal 5 core patch that improves compatibility with PHP 5.3. Drupal 5 will officially not support PHP 5.3 (see #853064: Alter INSTALL.txt to be clear PHP 5.3 is not compatible with Drupal 5), however some of us have no other choice and will have to make D5 work anyway.
Warning: You will have to patch many core/contributed modules as well, because of the severe PHP warning when a functions expects a reference parameter and a value is given; and the function will not be executed (example: #587568: Parameter 1 to comment_nodeapi() expected to be a reference module.inc, line 450 (php 5.3 compatibility)). In most cases the solution is to simply remove the '&' reference operator from the parameter, if the function does not need the reference.
PHP errors are logged to watchdog (admin/logs/watchdog), so if you hit broken subpages of your site visit the log where you can find the broken functions that expect references.
The patch was inspired by #360605: PHP 5.3 Compatibility
Comment | File | Size | Author |
---|---|---|---|
#34 | Issue-1016008-Drupal-5-PHP-53-54-compatibility-patch.patch | 13.82 KB | hass |
Comments
Comment #1
RobLoachThanks a lot... Here's another patch I uploaded from #853064. I haven't compared either one, just thought I'd keep it posted.
Comment #2
RobLoachWhoops, forgot the patch.
Comment #3
dpearcefl CreditAttribution: dpearcefl commentedClosing because there is no more work to be done.
Comment #4
NaX CreditAttribution: NaX commentedThanks a lot for these patches they helped me a great deal with a large number of D5 sites that I cant upgrade to D6.
If anybody else finds this post I thought I should add how I got around contrib module hooks where function were expecting references.
Example Error:
Parameter 2 to uc_payment_order() expected to be a reference, value given in includes/module.inc on line 436.
The problem is that I don't really have the time to investigate every hook call that causes errors like this and I cant blindly upgrade modules hoping they were fixed and I have a lot of sites that needed upgrading.
I solved this using the PHP5 Reflection API in module_invoke_all(), by looking up if a function arguments require to be passed by Reference before calling call_user_func_array().
I don't really know if this could cause other unforeseen errors, but it fixed a bunch of warnings for me so far.
I hope it helps.
Comment #6
RobLoachMight fork Drupal 5 instead of maintaining this patch.
NaX: Should that be part of this patch? Is that only for PHP 5?
Comment #7
RobLoachComment #8
NaX CreditAttribution: NaX commentedMy module_invoke_all hack will work on PHP4 and PHP5 because the passing by reference and value problem only became a problem in PHP 5.3 and the Reflection API was add in PHP5.1 (if I remember correctly). So because it does an
if class_exists
it will work on older and the latest PHP versions. If you want to add it to your patch is your call. It does sort of change how core works. Personally I think this could also be added to module_invoke but I have not found the need yet.Comment #9
Q-Zma CreditAttribution: Q-Zma commentedStill have WSOD on user edit page :(
Comment #10
RobLoachComment #11
Gomu CreditAttribution: Gomu commentedI had to move a Drupal 5 site to a hosting provider who supports only PHP5.3. The patch attached in comment #7 worked like a charm. Thanks a lot.
Comment #12
elvis2 CreditAttribution: elvis2 commentedThanks, #7 worked for me.
Comment #13
tonystark CreditAttribution: tonystark commentedI using Drupal 5.12, I have problem after I transfer hosting company and web hosting company are using is PHP 5.3.18
form.inc on line 218:-
$form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);
please help.
Comment #14
NaX CreditAttribution: NaX commented@tonystark
You will need manually upgrade to the lates Dev version of Drupal 5.x and manually apply the above patches. See #7
Comment #15
tonystark CreditAttribution: tonystark commentedI update script follow #7, but the problem still same...
Comment #16
NaX CreditAttribution: NaX commented@tonystark
You may also need to upgrade your contribute modules as well.
See the release notes for webform 5.x-2.9 - http://drupal.org/node/624966
If possible it would be best to upgrade to Drupal 6.x. To do that I would suggest doing a trial upgrade on a backup first.
Just remember to make backups of your database before doing any upgrades including contribute modules.
Comment #17
texas-bronius CreditAttribution: texas-bronius commentedThanks guys! And here I thought patching Drupal 5 for PHP5.3 was going to take me through dragons' lairs or some grandmother's dark basement with a pale skin, shirt torn, no bath in months old man with a long grey beard down to his toes, freelancing as a Fortran/COBOL aficionado.
(What I mean to say is #7 patch worked like a charm!)
Comment #18
hass CreditAttribution: hass commentedSeen this on
admin/logs/watchdog
:Comment #19
hass CreditAttribution: hass commentedFound the source of this bug in
project_release.module
menu hook. Here is the fix for 'callback arguments':Comment #20
RobLoachThanks hass... Made an issue in their queue: #1925580: Incorrect Callback Arguments
Comment #21
szt CreditAttribution: szt commentedSo it's fixed.
Comment #22
RobLoachUnfortunately this issue is not fixed since it hasn't been merged into Drupal 5. I haven't tested it since I posted it, and haven't forked it anywhere.
Comment #23
NaX CreditAttribution: NaX commentedI have started looking at PHP 5.4 and I thought I would share what I have found so far. This should be seen as changes after applying the above patch.
I found all these issues to be relevant.
#1812006: PHP 5.4 Illegal string offset 'data' in includes/tablesort.inc on line 110.
#996124: taxonomy_term_page() - Error: Creating default object from empty value taxonomy.pages.inc
#1680614: Illegal string offset 'region' and 'status' when saving block admin
My Drupal 5 version for this is:
And lastly, I also adapted the following patch that I we have used on D6 sites that removes E_STRICT again from error reporting. This removes a bunch of Views related warnings and notices on D6 but seems to be less useful in D5 but I still think its relevant.
I hope someone finds this helpful.
Comment #24
xenophyle CreditAttribution: xenophyle commentedI found that the change to the signature of user_user() caused a bug for me, but the rest of the changes for the user module were sufficient to fix the user-related errors.
Specifically, the change to user_user() caused all roles to be assigned to any user that was saved.
Comment #25
mcurry CreditAttribution: mcurry commentedThe 5.x-dev distro page shows a much older date than 5.23, so I'm not sure if it's the most current code base relative to 5.23. How can I tell if it's 'advisable' to run the 5.x-dev package, or if I can 'upgrade' to that if I've been using 5.23?
Edit: It does seem to apply cleanly to 5.x-dev, and 5.x-dev is marked with a VERSION string of 5.24-dev in modules/system/system.module so I assume it's the latest and greatest. I misread the date info on the 5.x-dev package page, so please disregard this message, I'm going ahead with the 5.x-dev (5.24-dev) release.
Comment #26
tooFATforBUTTer CreditAttribution: tooFATforBUTTer commentedI used a combination of NaX's suggestion in #4 and RobLoach's patch in #22.
The thing I like most about Nax's solution is it required a lot less code rewrite, however it's just an executed patch, so it does generate overhead. Also, I found that the call_user_func_array() function is scattered throughout our code base. I defined a new function in bootstrap.inc so I could reuse NaX's logic:
I did discover one problem with NaX's original code though. It assumes that the array of:
will have synchronized keys with the array of arguments being handed off to the $function. This broke some things for me, so I added an array of the keys used by $variables.
That seems to have properly synchronized $function parameters and $variables.
Great idea Nax! It really helped us out in a pinch! I'm sure I'll have a handful of other tweaks to do in the codebase, but this alone is 90%+ of the leg work.
Comment #27
tooFATforBUTTer CreditAttribution: tooFATforBUTTer commentedIf my comment in #26 is somewhat unclear, once you define the custom function " drupal_user_func_array", just call it right before a problematic "call_user_fanc_array" call.
The definition of "drupal_user_func_array" in comment #26 accepts $params as a reference and will correctly reformat it right before calling "call_user_func_array".
Comment #28
NaX CreditAttribution: NaX commented@tooFATforBUTTer
Nice catch with the argument / parameter keys, I see now how a function call that accepts a variable number of arguments would break with my code.
Thanks for the feedback.
Comment #29
miiimoooI couldn't really make sense out of xenophyle's #24 but I also found the issue with assigning all roles to a user when saving (PHP 5.4).
This change fixed the problem but I'm not sure whether its' correct:
Comment #30
David_Rothstein CreditAttribution: David_Rothstein commentedI ran into that issue too, and think it's the correct change (as well as other places where the patch made $edit no longer taken by reference). Since $edit is an array, it should still be taken by reference in cases where the function needs to modify it.
Attached patch makes those changes.
Comment #31
Ambrosy CreditAttribution: Ambrosy commentedHello David. Unfortunately there is problem with ampersand (&$args <=> $args) is not fixed in my case (Drupal 5.23 + PHP 5.3). I got the errors like 'Parameter 1 to phptemplate_field() expected to be a reference, value given in public_html/includes/theme.inc on sring 175' which I cannot solved yet. What could be the reason? So I need PHP 5.4 for this? Thanks.
Comment #32
secgeek CreditAttribution: secgeek commentedthanks patch mentioned in #30 worked for me. i am using it for http://rentsellmyhouse.com
Comment #33
chirale CreditAttribution: chirale commentedPatch #30 worked for me too. In my case (CentOS 6) I have to disable APC via apc.filters on /etc/php.d/apc.ini and to enable Short tags on /etc/php.ini (short_open_tag = On). Thank you David!
Comment #34
hass CreditAttribution: hass commentedAttached patch fixes some issues found in PHP 5.4.36. I have not found any other issues.
Url:
user/1/edit
URL
admin/logs/watchdog
and very many other urls:Comment #35
hass CreditAttribution: hass commentedFound one issue. Not sure how to fix
warning: Parameter 1 to profile_load_profile() expected to be a reference, value given in /includes/module.inc on line 387.
Comment #36
japerryDrupal 5 is unsupported. Cleaning up the issue queue.
Comment #37
RobLoachFor those who enjoy git, I've posted a Pull Request for this over at:
https://github.com/RobLoach/drupal/pull/5
https://github.com/RobLoach/drupal/pull/5.patch
https://github.com/RobLoach/drupal/pull/5.diff
Feel free to submit fixes over there.
Comment #38
reformatt CreditAttribution: reformatt commentedthanks Rob Loach! you will always be my Drupal hero ;)
the Drupal 5 patch worked magically