Object-valued by-reference arguments, trouble with PHP 5.3 call_user_func_array()

donquixote - September 6, 2009 - 04:15
Project:Views
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Issue tags:PHP 5.3
Description

Some of the functions in views are making trouble with PHP 5.3, due to call-by-reference arguments when the function is called via call_user_func_array.

Problems:
- Anything that wants to be called via module_invoke_all should be by-value, because any references are lost on the way.
- Any function that wants to be called via any other thing that uses call_user_func_array should be very careful about by-reference arguments, because in many cases the received argument value will not be a reference.
- Object-valued arguments don't need to be by-reference. They are pointers. Unless you want a reference to the pointer itself.
- $view is always an object.

I found a few of these functions in views/includes/admin.inc:
views_ui_regenerate_tabs
views_ui_build_form_state
views_ui_add_form_to_stack
views_ui_ajax_form (breaking the ajax functionality for PHP 5.3)
etc
and a lot of "&$views" in the code itself. Hey it's not necessary, object vars are pointers!! (or is this some weird PHP 4 stuff ?)

In most cases the solution is to simply remove the unnecessary "&".

#1

donquixote - September 7, 2009 - 01:13

I have to apologize, I did not do any research about PHP4. It turns out that PHP4 needs to have these object arguments passed by reference. How odd!

Still, something needs to be done for PHP 5.3, which will complain in some cases.
A good solution could be to use a custom function instead of module_invoke or module_invoke_all.

#2

thekevinday - September 17, 2009 - 14:02

subscribing

Removing the ampersand from the mentioned function calls seem to get past the most immediate symptoms.

#3

merlinofchaos - September 17, 2009 - 15:42

- Object-valued arguments don't need to be by-reference. They are pointers. Unless you want a reference to the pointer itself.

This is only true in PHP5. Views is PHP4 compatible and runs in PHP4 up through PHP5.2. We cannot make PHP5 only assumptions to make it work with PHP5.3 only to break things for the (larger) audience still running PHP4.

#4

Berdir - September 17, 2009 - 16:11

This is only true in PHP5. Views is PHP4 compatible and runs in PHP4 up through PHP5.2. We cannot make PHP5 only assumptions to make it work with PHP5.3 only to break things for the (larger) audience still running PHP4.

This is true. But...

a) It is not necessary to remove it to be PHP 5.3 compatible

b) The & is ignored by call_user_func_array. Calling by reference or by value *only* depends if the values in $params are by reference or not, see http://php.net/call_user_func_array. Yes, this is ugly.

This does have the following effect if such a function is called with call_user_func_array():

PHP4: It is simply called by value, changes are not stored and it might result in bugs.
PHP5 (< 5.3): It is called by value but the object itself is always by reference, so it works..
PHP5.3: A warning is issued and the value is set to NULL which breaks everything.

The solution is to avoid module_invoke_all() when by reference is required and instead use $function($param1, $param2, $param3).

#5

jbrauer - September 25, 2009 - 05:22

#6

merlinofchaos - September 25, 2009 - 16:01
Status:active» duplicate

http://drupal.org/node/452384

#7

NelM - October 10, 2009 - 22:06

Are there any patch coming out for views? or we really have to remove it one by one?

#8

thekevinday - October 20, 2009 - 16:06

I only noticed this by chance and I am not a views developer, so I cannot help you.

This bug report is closed because it is a duplicate, please use the link in post #6 to subscribe or join in on the issue as that is the active bug report.

#9

W32 - November 3, 2009 - 17:22

subscribing

 
 

Drupal is a registered trademark of Dries Buytaert.