date_plugin_display_attachment::options(&$display) wrongly assumes an object as argument.

donquixote - August 15, 2009 - 09:02
Project:Date
Version:6.x-2.4
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community
Description

warning: Attempt to modify property of non-object in [..]\sites\all\modules\contrib\date\includes\date_plugin_display_attachment.inc on line 24.

File: date/includes/date_plugin_display_attachment.inc
Class: date_plugin_display_attachment
Method: date_plugin_display_attachment::options(&$display)

<?php
 
function options(&$display) {
   
parent::options($display);
   
$display->display_options['style_plugin'] = 'date_nav';
   
$display->display_options['items_per_page'] = 0;
   
$display->display_options['row_plugin'] = '';
   
//$display->display_options['defaults']['style_plugin'] = FALSE;
   
$display->display_options['defaults']['style_options'] = FALSE;
   
$display->display_options['defaults']['items_per_page'] = FALSE;
   
$display->display_options['defaults']['row_plugin'] = FALSE;
   
$display->display_options['defaults']['row_options'] = FALSE;
  }
?>

Called here:
File: views/includes/base.inc, line 57
Class: views_object
Method: views_object::set_default_options()

<?php
 
/**
   * Set default options.
   * For backward compatibility, it sends the options array; this is a
   * feature that will likely disappear at some point.
   */
 
function set_default_options() {
   
$this->_set_option_defaults($this->options, $this->option_definition());

   
// Retained for complex defaults plus backward compatibility.
   
$this->options($this->options);
  }
?>

Problems/Questions:
- Obviously the argument is an array, whereas the function assumes an object.
- Moreover, I get the idea the function is not intend to take $this->options as the argument.
- If the argument is supposed to be an object, then why the call by reference?
- Where is that function supposed to be called with an object?

The problem did not cause any error messages before I moved to PHP 5.3. But in this case, I think it's quite obvious that the error message (or warning) is justified.

#1

designerbrent - September 2, 2009 - 15:53

subscribing

#2

arosemartin - September 3, 2009 - 22:21

subscribing

#3

thekevinday - September 14, 2009 - 19:20

This problem happens to me when I run update.php.

    * warning: Attempt to modify property of non-object in /var/www/html/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 24.
    * warning: Attempt to modify property of non-object in /var/www/html/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 25.
    * warning: Attempt to modify property of non-object in /var/www/html/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 26.
    * warning: Attempt to modify property of non-object in /var/www/html/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 28.
    * warning: Attempt to modify property of non-object in /var/www/html/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 29.
    * warning: Attempt to modify property of non-object in /var/www/html/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 30.
    * warning: Attempt to modify property of non-object in /var/www/html/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 31.

#4

izmeez - September 19, 2009 - 00:00

I encountered the same problem today while trying to bring a live site with Drupal 6.14 locally onto xampp 1.72 which is using PHP 5.3

I'll take a step back to an earlier version of xampp and see if it solves my problems.

Izzy

#5

karimansu - September 20, 2009 - 19:25

Same here.

This is my first time with Drupal and i am getting the same error.
XAMPP 1.72 over windows here.

And i am getting this too:
warning: Parameter 1 to admin_menu_admin_menu() expected to be a reference, value given in F:\xampp\htdocs\drupal\includes\module.inc on line 471.

#6

just_N - September 20, 2009 - 22:14
Version:6.x-2.x-dev» 6.x-2.4

This is happening to me on both Drupal 6.13 and 6.14 running php 5.3.

Running apache and php through Snow Leopard.

#7

Lars Vandergraaf - September 21, 2009 - 18:37

I get the following errors with 6.14. Modules installed: Core 6.14, CCK 6.x-2.5, Calendar 6.x-2.2, Date 6.x-2.4, Views 6.x-2.6. This is a XP OS and xampp 1.7.2 which includes PHP 5.3.

warning: Attempt to modify property of non-object in C:\xampp-win32-1.7.2\xampp\htdocs\drupal-6.14\modules\date\includes\date_plugin_display_attachment.inc on line 24.
(lines 24-31)

warning: Attempt to modify property of non-object in C:\xampp-win32-1.7.2\xampp\htdocs\drupal-6.14\modules\calendar\includes\calendar_plugin_display_page.inc on line 47.
(lines 47-55)

warning: Attempt to modify property of non-object in C:\xampp-win32-1.7.2\xampp\htdocs\drupal-6.14\modules\calendar\includes\calendar_plugin_display_block.inc on line 50.
(lines 50-58)

warning: Attempt to modify property of non-object in C:\xampp-win32-1.7.2\xampp\htdocs\drupal-6.14\modules\calendar\includes\calendar_plugin_display_attachment.inc on line 164.
(lines 164-167) 5 Times

If I toggle off calendar I only get the warning: Attempt to modify property of non-object in C:\xampp-win32-1.7.2\xampp\htdocs\drupal-6.14\modules\date\includes\date_plugin_display_attachment.inc on line 24.
(lines 24-31) which would indicate the date and view are not playing well together.

If I toggle off view and calendar, all errors go away as well as my cunning plan to include the ability to define events with a calendar.

PS. I have no skills at fishing, I live off the kindness of those that can fish.

#8

izmeez - September 21, 2009 - 18:26

The problem goes away with an earlier version of XAMPP with php 5.2.x
Also, if you are transferring data back and forth between test and live sites it was VERY important to make sure the xampp php version matches that on the live server.

Izzy

#9

Lars Vandergraaf - September 21, 2009 - 18:39

Do you have a link for an earlier version of xampp with php 5.2.x?

#10

thekevinday - September 21, 2009 - 20:54

For the time being I wrote a band-aid that just works around the warning.
This probably does not solve the problem, but on production systems it at least keeps things a little quieter until a proper solution is made.

all this patch does is wrap the problematic section in the following if condition:

<?php
 
if (is_object($display)){
  }
?>

AttachmentSize
date-6.x-2.x-fix_display_attachment_object-1.patch 1.41 KB

#11

izmeez - September 21, 2009 - 22:23

The XAMPP page gives a link to all earlier versions, they are housed on SourceForge. Look at the release notes to decide which you want. http://sourceforge.net/projects/xampp/files/

I believe,
1.6.8 uses php 5.2.6
1.70 uses php 5.2.8
1.7.1 uses 5.2.9
1.7.2 uses 5.3

#12

mikeytown2 - September 23, 2009 - 22:34

subscribe

#13

drasgardian - September 25, 2009 - 00:53

subscribing.

applied patch from #10 for the time being.

#14

kratib - October 6, 2009 - 23:43

subscribe

#15

davepoon - October 8, 2009 - 11:37

Same problem here.
I use acquia-drupal-1.2.16.5106, PHP5.3 and Zend Server CE.
Just subscribe this to wait for the update.

#16

Martijn de Wit - October 9, 2009 - 11:21

subscribe

The new PHP version is not only causing problems with Date...
I get errors with Admin and Views 2 !

I went back to PHP Version 5.2.9. Everything works fine now...

#17

ganglion - October 12, 2009 - 12:17

subscribing. The bug doesn't seem to break any calendar functions, so I'll try just applying patch #10.

#18

Geoffrey - October 13, 2009 - 19:02

subscribing

#19

Sree - October 15, 2009 - 06:47

subscribing

#20

vasike - October 17, 2009 - 07:34

subscribe
#10 works for me

#21

quinn - October 29, 2009 - 17:42

subscribe. does this work better?

<?php
   
if (is_object($display)) {
     
$display->display_options['style_plugin'] = 'date_nav';
     
$display->display_options['items_per_page'] = 0;
     
$display->display_options['row_plugin'] = '';
     
$display->display_options['defaults']['style_options'] = FALSE;
     
$display->display_options['defaults']['items_per_page'] = FALSE;
     
$display->display_options['defaults']['row_plugin'] = FALSE;
     
$display->display_options['defaults']['row_options'] = FALSE;
     
//$display->display_options['defaults']['style_plugin'] = FALSE;
   
}
    else {
     
$display['display_options']['style_plugin'] = 'date_nav';
     
$display['display_options']['items_per_page'] = 0;
     
$display['display_options']['row_plugin'] = '';
     
$display['display_options']['defaults']['style_options'] = FALSE;
     
$display['display_options']['defaults']['items_per_page'] = FALSE;
     
$display['display_options']['defaults']['row_plugin'] = FALSE;
     
$display['display_options']['defaults']['row_options'] = FALSE;
     
//$display->display_options['defaults']['style_plugin'] = FALSE;
   
}
?>

#22

Rosamunda - November 1, 2009 - 14:51

+1!

#23

W32 - November 3, 2009 - 12:38

I also have this warning.

Apache/2.2.13 (Win32) PHP/5.3.0

#24

W32 - November 3, 2009 - 17:30

No you should remove '&' in &$display argument.
In PHP 5.3 function must be: function options($display).

#25

kentr - November 4, 2009 - 04:27

+1

Agree with W32 that just removing the ampersand may be sufficient. Appears to be general php 5.3 pass by reference problem.

#26

kdhartstrom - November 5, 2009 - 17:20

I am also running PHP 5.3 and getting the error. I tried removing the & ampersand from the options function and I'm still getting the error.

So my date_plugin_display_attachment.inc line 22 reads:
function options($display) {

and i still the following errors when I visit the modules page:
* warning: Attempt to modify property of non-object in /home/drupal/drupal/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 24.
* warning: Attempt to modify property of non-object in /home/drupal/drupal/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 25.
* warning: Attempt to modify property of non-object in /home/drupal/drupal/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 26.
* warning: Attempt to modify property of non-object in /home/drupal/drupal/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 28.
* warning: Attempt to modify property of non-object in /home/drupal/drupal/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 29.
* warning: Attempt to modify property of non-object in /home/drupal/drupal/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 30.
* warning: Attempt to modify property of non-object in /home/drupal/drupal/sites/all/modules/date/includes/date_plugin_display_attachment.inc on line 31.

#27

appellation - November 5, 2009 - 17:38

Simply removing the ampersand did not work for me. Instead, I assumed that $display is an array. I'm not sure why it is expected to be an object, but I think I must be missing something.

This is related to an issue with the calendar module: http://drupal.org/node/613528, http://drupal.org/node/587424

#28

c.ex - November 6, 2009 - 14:48

Confirmed that removing the ampersand doesn't work. To clarify, PBR still works just fine, but passing variables by reference at runtime (calling foo(&$bar) rather than defining function foo(&$baz) and passing $bar) has been deprecated. See http://php.net/manual/en/language.references.pass.php.

#29

c.ex - November 6, 2009 - 18:51

Did some more digging... To the best of my understanding, the set_default_options() method in views_object (that ultimately calls this) exists mostly for backwards compatibility, and it always deals with arrays - not objects. So I'd agree that the warning is justified, and would add that patch #10 may break the backwards compatibility the function affords - albeit in a way harmless to most environments. In theory, it should only be getting an array, so testing whether it's an object should always result in a failure, leaving some defaults unset. It seems a better solution would be to do something similar to the else block in #21, manipulating the array as it was originally intended.

Anyone more familiar with the codebase, please feel free to correct me if I'm completely off-base here. :]

#30

c.ex - November 10, 2009 - 20:09
Status:active» needs review

Just tested the following fix; everything appears to work as it should. I just submitted a similar patch for review on the Calendar issue queue (http://drupal.org/node/613528#comment-2250424) for those interested. Review and feedback welcome!

AttachmentSize
date-6.x-2.x-549884-30.patch 1.4 KB

#31

fuerst - November 13, 2009 - 14:36
Status:needs review» reviewed & tested by the community

Patch works. I double checked by looking in the Views code for the options() method. Only found one in the class views_object which is empty and does lack documentation of its parameters. But by looking around it seems usual for the $option parameter to be an array, not an object.

#32

Ninja Overlord - November 19, 2009 - 21:04

Works for me as well.

#33

WSRyu - November 22, 2009 - 18:06

Nope, patch doesn´t work for me! this is the error i get upon clickin on save.

Parse error: parse error in C:\wamp\www\drupal-6_14\sites\all\modules\calendar\includes\calendar_plugin_display_page.inc on line 47

i edited the patch by hand and im pretty sure i did exactly as the patch mentioned.
any ideas?

#34

c.ex - November 22, 2009 - 23:06

What you have above is an issue with the calendar module, where you have already posted. Please be sure that you are posting in the right issue queue in the future.

#35

misahs - December 6, 2009 - 21:02

subscribing

 
 

Drupal is a registered trademark of Dries Buytaert.