Make Views compatible with PHP 5.3
Gerhard Killesreiter - May 3, 2009 - 18:26
| Project: | Views |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
| Issue tags: | PHP 5.3 |
Description
Currently, there is only one known issue: The 3rd argument of function views_ui_ajax_form should not be exclicitly marked as "passed by reference". PHP 5.3 chokes on this.

#1
See: http://drupal.org/node/569724
#2
subscribe
#3
Also a similar issue here:
warning: Parameter 3 to views_ui_build_form_state() expected to be a reference, value given in [site_path]/drupal-6.14/sites/all/modules/views/includes/admin.inc on line 1591.
#4
I'm also having the same issue:
Parameter 3 to views_ui_ajax_form() expected to be a reference, value given in D:\web\custom sites\kazerne_dossin\includes\menu.inc on line 348.
PHP 5.3
Drupal 6.14
#5
I kept getting an error that would pop-up saying i had an error in my views_ui_ajax_form()....
I found the error on line 1565 of includes/admin.inc
I removed the & in front of &$views. As of now, it's working.
#6
views/includes/admin.inc
on line 1559:
function views_ui_ajax_form($js, $key, &$view, $display_id) {
to:
function views_ui_ajax_form($js, $key, $view, $display_id) {
it works fine.
#7
@diewaldfee:
The & on object-valued parameters is needed for PHP 4, unfortunately.
I wish Drupal 6 had never tried to be PHP 4 compatible... but now it's too late.
#8
To my surprise the below code works.
<?php
print('Current PHP version: ' . phpversion() . "\n");
$my_var=phpversion();
if ($my_var[0] == "4"){
function views_ui_ajax_form() {
print("hi\n");
}
} else {
function views_ui_ajax_form() {
print("bye\n");
}
}
views_ui_ajax_form();
?>
If I set the $my_var[0] == "5" test while using php 5 series, then the last printed line will be "hi" instead of "bye"
The problem I see with this is the duplication of code..
I wonder if there is a way to truly do a #ifdef/#endif style coding as seen in C and C++ such that only the function name line gets changed based on php versions.
FYI: http://us3.php.net/manual/en/function.phpversion.php
#9
Well, we could have them both pass-through to the real function, so the duplicated code would be fairly short.
<?phpif (version_compare(phpversion(), 5, '<') {
function views_ui_ajax_form($js, $key, &$view, $display_id) {
return _function views_ui_ajax_form($js, $key, $view, $display_id);
}
} else {
function views_ui_ajax_form($js, $key, $view, $display_id) {
return _function views_ui_ajax_form($js, $key, $view, $display_id);
}
}
?>
Or something along those lines.
#10
Wouldn't the error still happen with php < 5?
After all, the internal function's $view is still _not_ getting passed by reference.
#11
greatly solved diewaldfeee, thanks alot!
greets,
Castell
#12
Could we make a list about where each of the problem functions is called? This would help to move forward.
For views_ui_ajax_form, the only place I find is as a menu callback. The $view object is generated by views_ui_cache_load(). I think menu callbacks don't support by-reference parameters, anyway. Maybe the trick in #9 could avoid one object copying in PHP 4. If we really want by-ref in a menu callback, we need something like this:
<?php
// called by menu system
function views_ui_cache_load($arg) {
...
return array(&$view);
}
function views_ui_ajax_form($js, $key, $view_packed, $display_id) {
$view = &$view_packed[0];
}
?>
#13
subscribe
diewaldfeee - borrowed your fix for the moment until something is patched. Many thanks.
#14
subscribe.
#15
#6 saved me for now
thanks
#16
subscribe
#17
subscribe
#18
After updating from the stable version to the dev version, 2 warnings remain, and view editing does not work properly.
Will the fixes be committed soon, or should users manually edit the module code for the time being?
Thank you
#19
subscribing - still seeing the error messages as well.
#20
subscribing
#21
I spent all morning looking for answers and finally found it here.
Ajax error fixed.
Thank you so much. :D
#22
#6 works for me !
#23
I can't solve this warning warning: Parameter 3 to views_ui_ajax_form() expected to be a reference, value given in localhost..\includes\menu.inc on line 348
there is no ampersand on this line and I don't know exactly, where can I put the written code here.
#24
after night spent trying to solve it I finally did it. Warning always come from localhost\mysite\includes\menu.inc on line 348. this confused me. then I try to serch for "&$view" in modules\view\includes and the in file admin and view deleted all ampersands befor "$view" and warning disappeared. maybe for this time is it ok, if there will be some problem again, I will search for ampersands in other files of includes folder of viewa module. for this time, everything is working.
#25
subscribe.
#26
#6 did it for me as well.. Thanks :)
#27
New snapshots on the dev branch keep having the problematic code.
Can't this be committed permanently?
#28
The problem is caused because by the compabiltiy to php4. Afaik Drupal itself does not support php 5.3. either.
#29
diewaldfeee #6 ... you are a genius!
Many Thanks,
Jan
#30
#28: D6 supports php 5.3 as of 6.14. http://drupal.org/node/360605
#31
Can sb commit this please? Its extremly bothering to change this manually on every update -.-
#32
Ok, I finally got around to getting a PHP4 install (pain in the wazoo, let me tell you) and tested without the & there, and things seem to be ok in PHP4. So I think that reference was not actually necessary. Things work fine without it in PHP5. Committed to all branches.
#33
subscribe
#6 worked fine for me on windows xp with Apache 2.2.11, MySQL 5.1.36 and PHP 5.3.0!
Thanks,
#34
#6 works, THNX!
#35
#6 worked for me too :))
big thanks ;)
#36
#6 Wonderful! This fix works for me (PHP 5.3)
#37
#6 Wonderful! This fix works for me . i from Viet Nam hehehe
#38
merlinofchaos: Thank you. 6.2-2.x-dev now seems to now be mostly working. I encountered the following warnings in a live preview of a view:
* warning: Parameter 3 to views_ui_build_form_state() expected to be a reference, value given in [site_path]\sites\all\modules\views\includes\admin.inc on line 1591.
* warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in [site_path]\includes\form.inc on line 371.
* warning: Invalid argument supplied for foreach() in [site_path]\sites\all\modules\views\includes\admin.inc on line 1527.
* warning: Attempt to assign property of non-object in [site_path]\sites\all\modules\views\includes\admin.inc on line 1598.
#39
Subscribe
#40
This patch fixes both the original problem and the latest problem that caused this to be reopened
edit: I want to emphasize: Please make sure that it is safe to remove the & at this location.
#41
Argh! I wish I saw this yesterday. Oh well. Changing status so this shows up in the right place, will get to this as soon as I can.
#42
Please consider not using my patch from #40, see my post here:
http://drupal.org/node/360605#comment-2340170
You may want to reconsider patch from #6 as well to any who applied that patch.
#43
For #6, I tested with PHP4 and confirmed that a reference was never actually needed there. I'll have to do the same for #40.
#44
subscribe