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

thekevinday - September 17, 2009 - 13:58

#2

donquixote - September 25, 2009 - 11:46

subscribe

#3

drasgardian - September 26, 2009 - 02:46

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

nicoknaepen - September 28, 2009 - 14:38

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

bobsather - September 29, 2009 - 01:04

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

diewaldfeee - September 29, 2009 - 19:25

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

donquixote - September 30, 2009 - 07:43

@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

thekevinday - September 30, 2009 - 13:38

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

merlinofchaos - September 30, 2009 - 17:57

Well, we could have them both pass-through to the real function, so the duplicated code would be fairly short.

<?php
 
if (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

thekevinday - September 30, 2009 - 19:12

Wouldn't the error still happen with php < 5?

After all, the internal function's $view is still _not_ getting passed by reference.

#11

Castell - October 5, 2009 - 16:59

greatly solved diewaldfeee, thanks alot!

greets,
Castell

#12

donquixote - October 5, 2009 - 18:20

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

fpdiver - October 9, 2009 - 16:18

subscribe

diewaldfeee - borrowed your fix for the moment until something is patched. Many thanks.

#14

ganglion - October 12, 2009 - 13:18

subscribe.

#15

hamsterbacke82 - October 13, 2009 - 06:17

#6 saved me for now
thanks

#16

bas.hr - October 19, 2009 - 18:58

subscribe

#17

vasike - October 20, 2009 - 06:29

subscribe

#18

marktheshark - November 1, 2009 - 02:36

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

trupal218 - November 2, 2009 - 02:28

subscribing - still seeing the error messages as well.

#20

W32 - November 3, 2009 - 16:32

subscribing

#21

mmbee888 - November 6, 2009 - 14:01

I spent all morning looking for answers and finally found it here.
Ajax error fixed.
Thank you so much. :D

#22

pduchateau - November 7, 2009 - 16:31

#6 works for me !

#23

obelus - November 7, 2009 - 20:56

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

obelus - November 8, 2009 - 09:10

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

somanyfish - November 12, 2009 - 17:23

subscribe.

#26

JeppeM - November 16, 2009 - 22:12

#6 did it for me as well.. Thanks :)

#27

marktheshark - November 17, 2009 - 11:36

New snapshots on the dev branch keep having the problematic code.

Can't this be committed permanently?

#28

dereine - November 17, 2009 - 17:49

The problem is caused because by the compabiltiy to php4. Afaik Drupal itself does not support php 5.3. either.

#29

jzigbe - November 18, 2009 - 18:49

diewaldfeee #6 ... you are a genius!
Many Thanks,

Jan

#30

peterjmag - November 18, 2009 - 19:51

#28: D6 supports php 5.3 as of 6.14. http://drupal.org/node/360605

#31

XerraX - November 19, 2009 - 13:57

Can sb commit this please? Its extremly bothering to change this manually on every update -.-

#32

merlinofchaos - November 20, 2009 - 22:04
Status:active» fixed

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

romainpi - November 23, 2009 - 15:15

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

WSRyu - November 25, 2009 - 10:19

#6 works, THNX!

#35

Rollaz - November 25, 2009 - 18:20

#6 worked for me too :))

big thanks ;)

#36

blitux - November 25, 2009 - 22:04

#6 Wonderful! This fix works for me (PHP 5.3)

#37

nguyenxuannghia - November 26, 2009 - 19:26

#6 Wonderful! This fix works for me . i from Viet Nam hehehe

#38

sutch - November 30, 2009 - 01:58
Status:fixed» needs work

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

xslim - December 1, 2009 - 09:06

Subscribe

#40

thekevinday - December 3, 2009 - 17:10

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.

AttachmentSize
views-6.x-2.7-php53-1.patch 1.01 KB

#41

merlinofchaos - December 3, 2009 - 18:33
Status:needs work» needs review

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

thekevinday - December 4, 2009 - 17:26

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

merlinofchaos - December 4, 2009 - 18:22

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

wernerglinka - February 1, 2010 - 23:27

subscribe

 
 

Drupal is a registered trademark of Dries Buytaert.