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 "&".

Comments

donquixote’s picture

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.

thekevinday’s picture

subscribing

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

merlinofchaos’s picture

- 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.

Berdir’s picture

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).

jbrauer’s picture

Issue tags:+PHP 5.3
merlinofchaos’s picture

Status:Active» Closed (duplicate)
NelM’s picture

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

thekevinday’s picture

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.

W32’s picture

subscribing

SepehrLajevardi’s picture

tracking.

kiamlaluno’s picture

You should subscribe to http://drupal.org/node/452384, as this report has been marked as duplicate of that report.

1hello2’s picture

# warning: Parameter 1 to profile_load_profile() expected to be a reference, value given in D:\xampp\htdocs\food\includes\module.inc on line 462.

I just slove the problem using PHP 5.3.thank you.

1hello2’s picture

object vars are pointers in PHP 5.3!!

kiamlaluno’s picture

@1hello2: This issue has been marked as duplicate of #452384: Make Views compatible with PHP 5.3 (but don't break it for PHP 4.x). You are barking to the wrong tree, here. :-)