Using Conditions 2.5 and PHP >= 5.2.0 result in the following PHP error being thrown:

Object of class stdClass could not be converted to string in modules/condition/condition.module on line 156.

This is due to PHP 5.2's handling of strings (it no longer automatically casts objects to strings - you need to explicitly specify a __toString() method. So, because of this, the array_intersect method used in the Condition module code resulted in an error (because array_intersect works using the following method: (string)$a === (string)$b, and this will fail if strings are not specified as parameters).

The code line in question:

return array_intersect($conditions, array_flip($cid));

The fix for this, is to simply use the built-in PHP function strcasecmp, which handles the string comparison that used to be implicit in array_intersect, but isn't anymore.

return array_uintersect($conditions, array_flip($cid), 'strcasecmp');

I would submit a patch, but I'm on windows, and I don't really know how to use diff that well. It's easier if a dev just changes it.

Comments

SpikeX’s picture

Oh, sorry, what I posted earlier doesn't work (and stupid Drupal doesn't let you edit your original posts...) This is the correct solution, since $conditions is actually an array of objects (not strings or numbers), and PHP doesn't know what to do with that, so you need to explicitly specify how to intersect the arrays. So, change that return statement like this:

return array_uintersect($conditions, array_flip($cid), '_cond_cmp');

And then add in a function to compare them using the "cid" member, like so:

function _cond_cmp($a, $b)
{
	if($a->cid == $b)
	{
		return 0;
	}
	if($a->cid > $b) return 1;
	return -1;
}

Notice how $a is the instance of $conditions, and we reference "cid" inside of it, to compare to the $cid list.

pfrenssen’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Drupal 6 is unsupported, closing.