I have a clean setup of Drupal 6.19 on PHP 5.3.2 and after trying to attach a file to any node I see the following warnings in the attachment fieldset of the form.

* warning: Parameter 2 to date_form_alter() expected to be a reference, value given in /var/www/trunk/includes/common.inc on line 2883.
* warning: Parameter 2 to date_timezone_form_alter() expected to be a reference, value given in /var/www/trunk/includes/common.inc on line 2883.

I have created a patch which removes the pointer from the $form_state argument because it does not appear to be updated and this eliminates those warning messages.

Comments

mvc’s picture

I'm not sure I completely understand what's going on here. I realize that drupal_alter() does allow passing arguments by reference where needed, but afaict it isn't necessary here.

Here is the call stack:

  1. function date_form_alter(&$form, &$form_state, $form_id)
  2. function date_content_display_form(&$form, &$form_state)
  3. function date_formatter_settings($form_state = NULL, $field, $options = array(), $views_form = FALSE)
  4. function _date_formatter_settings($form_state = NULL, $field, $options = array(), $views_form = FALSE)

So, $form_state is passed by reference to date_form_alter() which passes it by reference to date_content_display_form(). From here it gets passed by value to date_formatter_settings() and then _date_formatter_settings(). The first three functions seem to do nothing with this value except to pass it to the next function in the list, and _date_formatter_settings() doesn't even use this value.

Either $form_state is there for possible future use, or it's being used in some clever way I'm not immediately seeing because I am not wise in the ways of the Drupal form API. Assuming the first case this patch should be safe, but at minimum I think that for consistency it should also change date_content_display() to not call $form_state by reference either.

mvc’s picture

StatusFileSize
new1.91 KB

revised patch which changes date_content_display() as described above

physiotek’s picture

thanks a lot for the patch.
i had this error and it was very annoying.

haggins’s picture

same here - patch working.
However, the problem seems to be elsewhere because passing $form_state as reference deliveres correct function signature according to FormsAPI.

tangent’s picture

@mvc, good catch. Your patch works for me.

@haggins, this warning appears on a clean install of Drupal 6.20 on PHP 3.5.3 with no other contrib module installed than the date modules. If the problem is elsewhere then it's in drupal_alter(). As mvc said, regardless of where the problem is, if *_form_alter() does not need to modify $form_state then there is no reason to use it as a reference. Removing the & will resolve the warning whether $form_state is passed as a reference or not.

haggins’s picture

As I get this warnings on a whole bunch of modules that implement hook_form_alter() there seems to be something wrong in drupal core. I will try 6.20 later (currently using 6.19).

edit: updating core to 6.20 doesn't help

thomas1977’s picture

StatusFileSize
new109.35 KB

Same here. The issue is probably not related to Date (not sure). I get a whole bunch of the warnings whenever I try to attach a file to a node - including warnings related to Date. See attached screenshot. BTW: using Drupal 6.20

mvc’s picture

Version: 6.x-2.6 » 6.x-2.7
StatusFileSize
new2.29 KB

Updated patch for 6.x-2.7

chey’s picture

Having the same issue.

PHP 5.3.3
Drupal 6.20

Is the patch in #8 going to show up in a stable release anytime soon?

mvc’s picture

@chey your help is needed with that -- first the patch needs to be reviewed! please try the patch, and whether it works for you or not, report your experiences here. when it's been tested and shown to work, the maintainer will know it's okay to add.

see http://drupal.org/patch/review if you've never done this before.

Countzero’s picture

StatusFileSize
new2.23 KB

The patch doesn't apply to 2.7, I think because the paths are wrong like in

--- a/sites/all/modules/patched/date/date/date.module
+++ b/sites/all/modules/patched/date/date/date.module

The 'patched' part shouldn't be there I guess. Corrected version attached. Applies and makes errors disappear.

choster’s picture

Title: Warning on PHP 5.3 when attaching file to node » Warning on PHP 5.3: date_form_alter() expected to be a reference, value given
Version: 6.x-2.7 » 6.x-2.x-dev
jackalope’s picture

The patch in #11 worked well for me.

jmwhitco’s picture

Patch in #11 worked for me. I no longer get the two date related errors when uploading a file. Running D6.21 with PHP 5.32.

mvc’s picture

Status: Needs review » Reviewed & tested by the community

setting to RTBC based on multiple positive reviews

monotaga’s picture

Are you sure this isn't related to #925580: Upload throws warnings on PHP 5.3?

arlinsandbulte’s picture

Status: Reviewed & tested by the community » Fixed

I think this was fixed here:
#925580: Upload throws warnings on PHP 5.3

Status: Fixed » Closed (fixed)
Issue tags: -file attachments, -php5.3

Automatically closed -- issue fixed for 2 weeks with no activity.