The majority of the errors I am getting are of the form:
'Parameter n to function_name() /expected to be a reference, value given/ in //path/to/file/ on line m//.'
This error is a known issue with PHP 5.3 and drupal from what I have read so far.
I have seen a few reported issues where people are recommending finding the relevant function and changing the parameter definition from '&$variable' to just '$variable'.
But I'm worried that this is just a quick fix which might throw up problems elsewhere - I don't really know either PHP or the drupal codebase well enough to know for sure what is the right way to fix these problems.
andy
Daniel Horning wrote:
could you be a tiny bit more specific as to the errors you are getting
also - you might want to check your error display settings in both PHP.ini's and see if they are the same it could just be that the errors were occurring on your test server and you might not have been seeing them.
-- Dan Horning
American Digital Services - Where you are only limited by imagination. dan.horning@planetnoc.com :: http://www.americandigitalservices.com 1-518-444-0213 x502 . toll free 1-800-863-3854 . fax 1-888-474-6133 15 Third Street, PO Box 746, Troy, NY 12180 (by appointment only)
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of andy baxter Sent: Tuesday, October 13, 2009 12:30 PM To: support@drupal.org Subject: [support] PHP 5.3 upgrade problems
Hi all,
I have recently moved a site from my test server (which is running php 5.2) to the live server (which is running php 5.3).
Since doing this, a lot of pages are throwing error messages about a function expecting a reference argument.
I have done enough research to get some idea of what the basic problem is, but still don't feel that I understand it well enough to dive in to trying to patch the code. So far all I have done is add something to the template to suppress warnings for non-admin users.
If anyone can help with this, I would appreciate it - the site is going public in two days and I still have some other things I need to sort out before then. Does anyone know of any well written explanations on-line of how this issue has come about and how it affects drupal? Or if someone on the list could take the time to explain to me what the issue is, that would be good as well.
cheers,
andy
[ Drupal support list | http://lists.drupal.org/ ]
andy baxter wrote:
The majority of the errors I am getting are of the form:
'Parameter n to function_name() /expected to be a reference, value given/ in //path/to/file/ on line m//.'
This error is a known issue with PHP 5.3 and drupal from what I have read so far.
I have seen a few reported issues where people are recommending finding the relevant function and changing the parameter definition from '&$variable' to just '$variable'.
But I'm worried that this is just a quick fix which might throw up problems elsewhere - I don't really know either PHP or the drupal codebase well enough to know for sure what is the right way to fix these problems.
What I really want to know is, if I find the (relatively few) places in the code where php5.3 is causing an issue that actually breaks site functions, and apply the fix above (i.e. &$variable -> $variable) or something similar, is this a good way of solving the problem for the time being, given that the site goes public on thursday, or is it just going to break something else, or cause other problems like security holes or whatever?
It seems to have stopped the error in the couple of places I've already tried it, but it worries me to just convert a pass-by-reference into a straight parameter pass like this. I like to understand what I am doing rather than just apply a patch, which is why I was asking if anyone can explain a bit more about what's going on here?
cheers,
andy
On Wednesday 14 October 2009 12:02:28 am andy baxter wrote:
What I really want to know is, if I find the (relatively few) places in the code where php5.3 is causing an issue that actually breaks site functions, and apply the fix above (i.e. &$variable -> $variable) or something similar, is this a good way of solving the problem for the time being, given that the site goes public on thursday, or is it just going to break something else, or cause other problems like security holes or whatever?
It seems to have stopped the error in the couple of places I've already tried it, but it worries me to just convert a pass-by-reference into a straight parameter pass like this. I like to understand what I am doing rather than just apply a patch, which is why I was asking if anyone can explain a bit more about what's going on here?
cheers,
andy
What functions are we talking about? The answer to that will vary per the exact function being called.
Vis, show us da codez!
Larry Garfield wrote:
On Wednesday 14 October 2009 12:02:28 am andy baxter wrote:
What I really want to know is, if I find the (relatively few) places in the code where php5.3 is causing an issue that actually breaks site functions, and apply the fix above (i.e. &$variable -> $variable) or something similar, is this a good way of solving the problem for the time being, given that the site goes public on thursday, or is it just going to break something else, or cause other problems like security holes or whatever?
It seems to have stopped the error in the couple of places I've already tried it, but it worries me to just convert a pass-by-reference into a straight parameter pass like this. I like to understand what I am doing rather than just apply a patch, which is why I was asking if anyone can explain a bit more about what's going on here?
cheers,
andy
What functions are we talking about? The answer to that will vary per the exact function being called.
Vis, show us da codez!
OK, as an example, this is the log entry for one of the errors that is coming up:
Type php Date Tuesday, 13 October, 2009 - 18:10 User experiment http://www.lancs.ac.uk/fass/drupal/expt/users/experiment Location http://www.lancs.ac.uk/fass/drupal/expt/profile/experimentalist/edit Referrer http://www.lancs.ac.uk/fass/drupal/expt/profile/experimentalist Message /Parameter 1 to theme_imagefield_widget() expected to be a reference, value given/ in //export/depts/fass/drupal/expt/includes/theme.inc/ on line /617/. Severity error Hostname 83.216.128.236 Operations
This is one of the errors that actually breaks site functions - the upload image box doesn't come up on the edit profile page.
I have grepped for the function name and found this: andy@anthill:/local/www/experiment$ grep -R 'function.*theme_imagefield_widget' * sites/all/modules/imagefield/imagefield.module:function theme_imagefield_widget_preview($item = NULL) { sites/all/modules/imagefield/imagefield.module:function theme_imagefield_widget_item($element) { sites/all/modules/imagefield/imagefield_widget.inc:function theme_imagefield_widget(&$element) {
I assume that the last declaration is the relevant one because of the '&$element'. This function looks like this:
/** * FormAPI theme function. Theme the output of an image field. */ function theme_imagefield_widget(&$element) { drupal_add_css(drupal_get_path('module', 'imagefield') .'/imagefield.css'); return theme('form_element', $element, $element['#children']); }
Here is another one, which doesn't break anything serious as far as I can tell:
Type php Date Tuesday, 13 October, 2009 - 23:28 User experiment http://www.lancs.ac.uk/fass/drupal/expt/users/experiment Location http://www.lancs.ac.uk/fass/drupal/expt/blog/previously-test/edit Referrer http://www.lancs.ac.uk/fass/drupal/expt/blog/previously-test/edit Message /Parameter 1 to content_diff() expected to be a reference, value given/ in //export/depts/fass/drupal/expt/includes/module.inc/ on line /471/. Severity error Hostname 83.216.128.236 Operations
Same procedure: andy@anthill:/local/www/experiment$ grep -R 'function.*content_diff' * sites/all/modules/cck/includes/content.diff.inc:function content_diff(&$old_node, &$new_node) { sites/all/modules/cck/includes/content.diff.inc: $function = $field_types[$field['type']]['module'] . '_content_diff_values'; sites/all/modules/cck/includes/content.diff.inc: $function = function_exists($function) ? $function : 'content_content_diff_values'; sites/all/modules/cck/includes/content.diff.inc:function content_content_diff_values($node, $field, $items) { sites/all/modules/cck/includes/content.diff.inc: function userreference_content_diff_values($node, $field, $items) { sites/all/modules/cck/includes/content.diff.inc: function nodereference_content_diff_values($node, $field, $items) { sites/all/modules/cck/content.module: if (module_exists('diff') && !function_exists('content_diff')) {
Here it looks like the first line above; the function looks like this: /** * Implementation of hook_diff() */ function content_diff(&$old_node, &$new_node) { $result = array(); // Prevent against invalid 'nodes' built by broken 3rd party code. if (isset($new_node->type)) { $type = content_types($new_node->type); $field_types = _content_field_types(); foreach ($type['fields'] as $field) { // Ignore fields the current user is not allowed to view. if (!content_access('view', $field, NULL, $new_node)) { continue; } $function = $field_types[$field['type']]['module'] . '_content_diff_values '; $function = function_exists($function) ? $function : 'content_content_diff _values'; $old_values = array(); $new_values = array(); if (isset($old_node->$field['field_name'])) { $old_values = $function($old_node, $field, $old_node->$field['field_name ']); } if (isset($new_node->$field['field_name'])) { $new_values = $function($new_node, $field, $new_node->$field['field_name']); } if ($old_values || $new_values) { $result[$field['field_name']] = array( '#name' => $field['widget']['label'], '#old' => $old_values, '#new' => $new_values, '#weight' => $field['widget']['weight'], '#format' => array( 'show_header' => FALSE, ), ); } } } return $result; }
I could just remove the & in front of the parameter name in both cases, but doing that without understanding what I am doing makes me nervous. Why would another function be passing a variable by value when the function expects a reference? Is this just bad coding which PHP <5.3 used to cover for, or some older feature which has been removed?
You could tell me in each case whether you think this hack is safe to use, or suggest another one, but what I really need is some better understanding of what's happening and why this situation has come about so I can do it myself - there are over 400 files in my installation which include functions with variable declarations like this, so presumably I can't just change all of them from &$ to $.
andy
Quoting andy baxter andy@earthsong.free-online.co.uk:
I assume that the last declaration is the relevant one because of the '&$element'. This function looks like this:
/**
- FormAPI theme function. Theme the output of an image field.
*/ function theme_imagefield_widget(&$element) { drupal_add_css(drupal_get_path('module', 'imagefield') .'/imagefield.css'); return theme('form_element', $element, $element['#children']); }
It isn't necessarily the definition of the function that is wrong. It is the data being passed to the function as it is defined that is the problem. You need to find all the uses of theme_imagefield_widget and make sure that the data being used in the parameter is a variable.
I could just remove the & in front of the parameter name in both cases, but doing that without understanding what I am doing makes me nervous. Why would another function be passing a variable by value when the function expects a reference? Is this just bad coding which PHP <5.3 used to cover for, or some older feature which has been removed?
The & means "by reference". See http://php.net/manual/en/language.references.pass.php for explanations. You'll quickly see what should be fixed.
-- Earnie -- http://r-feed.com/ -- http://for-my-kids.com/ -- http://www.4offer.biz/ -- http://give-me-an-offer.com/
Earnie Boyd wrote:
Quoting andy baxter andy@earthsong.free-online.co.uk:
I assume that the last declaration is the relevant one because of the '&$element'. This function looks like this:
/**
- FormAPI theme function. Theme the output of an image field.
*/ function theme_imagefield_widget(&$element) { drupal_add_css(drupal_get_path('module', 'imagefield') .'/imagefield.css'); return theme('form_element', $element, $element['#children']); }
It isn't necessarily the definition of the function that is wrong. It is the data being passed to the function as it is defined that is the problem. You need to find all the uses of theme_imagefield_widget and make sure that the data being used in the parameter is a variable.
This is what I was afraid of - there are quite a few of these errors coming up. Most seem to be non-fatal, but I still would like to sort them out if possible.
I have seen it suggested just to remove the & in cases where the function is expecting an object. Does this make sense in PHP terms?
andy
Quoting andy baxter andy@earthsong.free-online.co.uk:
I have seen it suggested just to remove the & in cases where the function is expecting an object. Does this make sense in PHP terms?
Unless the function is defined incorrectly and doesn't use the purpose of pass by reference then it is absolutely incorrect to remove the & from the parameter. A pass by reference parameter allows changes to the external data. If you remove & then the changes become local to the function and the resultant change is not seen externally.
<?php $a = 1; $b = 2;
function c(&$c) { $c = $c * 2; }
c($a); c($b);
print $a . "\n"; print $b . "\n"; ?>
Result: 2 4
<?php $a = 1; $b = 2;
function c($c) { $c = $c * 2; }
c($a); c($b);
print $a . "\n"; print $b . "\n"; ?>
Result: 1 2
-- Earnie -- http://r-feed.com/ -- http://for-my-kids.com/ -- http://www.4offer.biz/ -- http://give-me-an-offer.com/
Earnie Boyd wrote:
Quoting andy baxter andy@earthsong.free-online.co.uk:
I have seen it suggested just to remove the & in cases where the function is expecting an object. Does this make sense in PHP terms?
Unless the function is defined incorrectly and doesn't use the purpose of pass by reference then it is absolutely incorrect to remove the & from the parameter. A pass by reference parameter allows changes to the external data. If you remove & then the changes become local to the function and the resultant change is not seen externally.
OK. thanks.
It depends on the parameter type.
If your parameter is a primitive type (int, string, float, bool) or an array, value will be used (this will be a local variable into your function), but if you pass a class (stdClass or any other) then it will be a reference, whether you wrote the & or not.
Regards, Pierre.
On Thu, 2009-10-15 at 12:35 +0000, Earnie Boyd wrote:
Quoting andy baxter andy@earthsong.free-online.co.uk:
I have seen it suggested just to remove the & in cases where the function is expecting an object. Does this make sense in PHP terms?
Unless the function is defined incorrectly and doesn't use the purpose of pass by reference then it is absolutely incorrect to remove the & from the parameter. A pass by reference parameter allows changes to the external data. If you remove & then the changes become local to the function and the resultant change is not seen externally.
<?php $a = 1; $b = 2; function c(&$c) { $c = $c * 2; } c($a); c($b); print $a . "\n"; print $b . "\n"; ?>
Result: 2 4
<?php $a = 1; $b = 2; function c($c) { $c = $c * 2; } c($a); c($b); print $a . "\n"; print $b . "\n"; ?>
Result: 1 2
-- Earnie -- http://r-feed.com/ -- http://for-my-kids.com/ -- http://www.4offer.biz/ -- http://give-me-an-offer.com/
Pierre Rineau wrote:
It depends on the parameter type.
If your parameter is a primitive type (int, string, float, bool) or an array, value will be used (this will be a local variable into your function), but if you pass a class (stdClass or any other) then it will be a reference, whether you wrote the & or not.
This is what I was thinking it might be. I've programmed in other languages before but not PHP, and I didn't know how PHP deals with things like this.
Thanks,
andy
andy baxter wrote:
Pierre Rineau wrote:
It depends on the parameter type.
If your parameter is a primitive type (int, string, float, bool) or an array, value will be used (this will be a local variable into your function), but if you pass a class (stdClass or any other) then it will be a reference, whether you wrote the & or not.
This is what I was thinking it might be. I've programmed in other languages before but not PHP, and I didn't know how PHP deals with things like this.
Thanks,
andy
Not entirely true, actually. In PHP 5, objects are split into the actual object and a handle to that object. The handle passes by value, but the object itself is still the same one being referenced. So it behaves about 93% of the time as if objects pass by reference. There are edge cases where that's not true, however, so don't get into the "object => pass by ref" trap. It's only "true" 93% of the time. :-)
--Larry Garfield
Hi, I'd like to create a page type of a few text areas, then pairs of image / text box rows. The part I'm having trouble with is that I'd like the number of image/text pairs to be variable. Preferably with a little javascript or js/ajax to append pairs when editing.
For the image I'd like an image upload box.
I can think of how to do this with views, but not how to do it in a single node. Any suggestions?
Thanks. -Don-
If I understand correctly, you should use the Image Field module (requires CCK, Image API and Filefield modules). Add a single image field when creating your content type and set it to allow multiple values. That will do what you are describing.
Best regards,
Tony
On Oct 14, 2009, at 10:21 PM, Don Pickerel wrote:
Hi, I'd like to create a page type of a few text areas, then pairs of image / text box rows. The part I'm having trouble with is that I'd like the number of image/text pairs to be variable. Preferably with a little javascript or js/ajax to append pairs when editing.
For the image I'd like an image upload box.
I can think of how to do this with views, but not how to do it in a single node. Any suggestions?
Thanks. -Don-
-- [ Drupal support list | http://lists.drupal.org/ ]
Thanks for the quick reply Tony. The part I'm unsure of is the text alongside the image.
What I'm looking for is a general description at the top of the page, then a photo and a narrative in rows at the bottom of the page. I'm taking an old site and migrating it to Drupal while updating the information at the same time. Here's a good example except for the 21st century theming..
http://www.centralcoasttourist.com/Parks_n_Recreation/State/Montana_de_Oro/R idgeTr/ridge1.html
-Don-
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Tony Zielinski Sent: Wednesday, October 14, 2009 10:27 PM To: support@drupal.org Subject: Re: [support] new content type with image/text box
If I understand correctly, you should use the Image Field module (requires CCK, Image API and Filefield modules). Add a single image field when creating your content type and set it to allow multiple values. That will do what you are describing.
Best regards,
Tony
I ran into this same problem the other day. It's like you want to create a field group, with an image field and textarea field, and then allow the user to add multiple of these field groups. As an alternative,
1) use the title attribute for the image and then some jquery to create image captions 2) use node reference to nodes that contain the image and text areas.
Neither of which I was totally happy with. (Option #1 worked great for me with small amounts of text.) Good luck.
- John
************************************************** John Callahan, Geospatial Application Developer Delaware Geological Survey, University of Delaware Email: john.callahan@udel.edu **************************************************
Don Pickerel wrote:
Thanks for the quick reply Tony. The part I'm unsure of is the text alongside the image.
What I'm looking for is a general description at the top of the page, then a photo and a narrative in rows at the bottom of the page. I'm taking an old site and migrating it to Drupal while updating the information at the same time. Here's a good example except for the 21st century theming..
http://www.centralcoasttourist.com/Parks_n_Recreation/State/Montana_de_Oro/R idgeTr/ridge1.html
-Don-
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Tony Zielinski Sent: Wednesday, October 14, 2009 10:27 PM To: support@drupal.org Subject: Re: [support] new content type with image/text box
If I understand correctly, you should use the Image Field module (requires CCK, Image API and Filefield modules). Add a single image field when creating your content type and set it to allow multiple values. That will do what you are describing.
Best regards,
Tony
John Callahan ha scritto:
I ran into this same problem the other day. It's like you want to create a field group, with an image field and textarea field, and then allow the user to add multiple of these field groups. As an alternative,
field groups for cck 2.x ?
M.
Michel Morelli ha scritto:
John Callahan ha scritto:
I ran into this same problem the other day. It's like you want to create a field group, with an image field and textarea field, and then allow the user to add multiple of these field groups. As an alternative,
field groups for cck 2.x ?
Sorry, I want to say the same "field groups" inserted more and more time ("Add another item").
M.
Exactly. I've thought of making a node type and then appending them. I guess I could add them as nodes like imagex.
Wonder if anyone would be interested if I wrote such a module. My contract is running out and I might have some spare time.
-Don-
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of John Callahan Sent: Thursday, October 15, 2009 4:45 AM To: support@drupal.org Subject: Re: [support] new content type with image/text box
I ran into this same problem the other day. It's like you want to create a field group, with an image field and textarea field, and then allow the user to add multiple of these field groups. As an alternative,
1) use the title attribute for the image and then some jquery to create image captions 2) use node reference to nodes that contain the image and text areas.
Neither of which I was totally happy with. (Option #1 worked great for me with small amounts of text.) Good luck.
- John
************************************************** John Callahan, Geospatial Application Developer Delaware Geological Survey, University of Delaware Email: john.callahan@udel.edu **************************************************