I got warnings from my drupal installation after switching servers, turns out the update from PHP 5.2.* to PHP 5.3 was far from harmless.

The warnings were of the kind "expected to be a reference, value given" and in my case was imageapi_gd_image_resize. It prevented images from loading with imagecache.

Seemingly same problem as 360605. Figured it could be useful to know about it for the imageAPI-devs.

Comments

drasgardian’s picture

I think I hit the same problem. Error looked like this:

Warning: Parameter 1 to imageapi_gd_image_resize() expected to be a reference, value given in [site path]/drupal-6.14/sites/all/modules/imageapi/imageapi.module on line 165

I corrected it by removing the "&" from

function imageapi_gd_image_resize(&$image, $width, $height)

inside imageapi_gd.module

drewish’s picture

yeah that should be alright since $image is an object and all objects are passed by reference in PHP 5. same change probably needs to be made to imageapi_gd_image_crop(), imageapi_gd_image_rotate(), imageapi_gd_image_sharpen(), and imageapi_gd_image_desaturate().

jbrauer’s picture

Issue tags: +PHP 5.3
eforth’s picture

Title: Error with PHP 5.3 » Error with PHP 5.3 - Feedback

This solution worked for me as well

eforth’s picture

This solution worked for me. I also had to remove the "&" from the following lines in order to keep ImageCache 100% working:

function imageapi_gd_image_rotate(&$image
function imageapi_gd_image_sharpen(&$image

drewish’s picture

Title: Error with PHP 5.3 - Feedback » Error with PHP 5.3

to be clear it works fine with our with out them it's just throwing warnings.

NelM’s picture

thanks a lot for this! been racking my brains the past couple of days about the warning, and on another note, It will not work fine with ubercart installed, the image won't appear. so to be safe just delete the "&", again many thanks!

infojunkie’s picture

Worked for me too! Thanks.

jdelaune’s picture

Status: Active » Needs review
FileSize
2.18 KB

Worked so well I made it into a patch...

VM’s picture

Version: 6.x-1.6 » 6.x-1.x-dev

patches would have to apply to 6.x-1.x-dev so that they can be rolled into the next release by the developer if they pass the muster.

szb100’s picture

subscribing

nicholasThompson’s picture

The other way is to fix the ImageAPI.module...

Index: imageapi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imageapi/imageapi.module,v
retrieving revision 1.23.2.3
diff -u -p -r1.23.2.3 imageapi.module
--- imageapi.module     18 Mar 2009 08:35:59 -0000      1.23.2.3
+++ imageapi.module     26 Oct 2009 10:04:03 -0000
@@ -161,7 +161,7 @@ function imageapi_default_toolkit() {
 function imageapi_toolkit_invoke($method, &$image, array $params = array()) {
   $function = $image->toolkit . '_image_' . $method;
   if (function_exists($function)) {
-    array_unshift($params, $image);
+    array_unshift($params, &$image);
     return call_user_func_array($function, $params);
   }

Adding this fixed the problem for me.

willazilla’s picture

Unless you take away the ampersand from the listed functions, the picture does not show up for Ubercart. It throws a warning, and fails to provide the photo that's been uploaded to an Ubercart product page. You must make the change or it's not fine.

Thanks everybody!!

drewish’s picture

FileSize
5.3 KB

we need to hit the imagemagick code too. i incorporated nicholasThompson's change since it seemed to make sense.

mairav’s picture

Thanks! It worked for me too with the patch given in #14 by drewish. I hope this can be added to the dev version.

dom_b’s picture

warning: Parameter 1 to imageapi_gd_image_resize() expected to be a reference

same error with lots of modules.

drewish’s picture

dom_b, was that after applying the patch?

dom_b’s picture

i've applied the patch to the latest cvs and it seems to work great now. thanks.

is this going to be rolled into the next release? as everything is working now I don't want to move to a stable version just for it to not be working again!

Deciphered’s picture

Status: Needs review » Reviewed & tested by the community

Patch worked for me.

Deciphered’s picture

Status: Reviewed & tested by the community » Needs work

I take that back, while the patch does fix issues with PHP 5.3, it creates issues for < PHP 5.3.

Needs work.

Cheers,
Deciphered.

jcnventura’s picture

Status: Needs work » Needs review

Looking at it, I think that applying only the patch in #12 should work.. Actually, mixing both as drewish did in #14 is precisely what should NOT be done. The patch in #9 switches the image argument from being passed by value to being passed by reference. The patch in #12 corrects the code to actually store the argument as reference and not as value. Mixing both is actually weird as now the value will be passed by reference, but expected to be a value (in the current code it is passed by value, but expected to be a reference).

In my site, applying #12 only makes the warnings disappear, although the imagecache_actions actions don't work, but I think that's unrelated as they don't work when I delete all the '&' in the functions as in the #9 patch anyway... The crop and resize stuff seem to work OK.

João

p0pemar1naru’s picture

I think Deciphered #20 is right. Less headbanging to just remove the "&" as a quick and dirty solution.
Nick

jcnventura’s picture

FileSize
674 bytes

Adding the '&' as in #12, is:

a) simpler;
b) the right thing to do, as the problem is indeed that missing '&' and nothing else;
c) doesn't change the API, so other modules won't need to change their calls (assuming they do it correctly).

Anyway, I am attaching #12 as a proper patch, and I will be testing this in a PHP < 5.3 today.

vannus’s picture

with 6.x-1.6 thumbnails where broken for me with php 5.3.0.

#23 patch with & works fine, glad it was here.

jcnventura’s picture

Status: Needs review » Reviewed & tested by the community

I have tested this patch with PHP 5.2.6 and it behaves as before.

This is such a simple change that with the successful reviews in #12, mine in #23 and the one in #24, I feel able to change the status to 'RTBC'.

João

bkat’s picture

Actually the change suggested in #12 is not correct. PHP 5.2.11 kindly informs me
PHP Warning: Call-time pass-by-reference has been deprecated in $file line $line. I don't get that warning on PHP 5.3.1

Here's a little test function that does pretty much what imageapi_toolkit_invoke() does:

<?php
class X {
    var $key;
}

function testme($a)
{
    $a->key = 'new';
    echo "a = {$a->key}\n";
}

function test1(&$i, $args)
{
    array_unshift($args, &$i);
    call_user_func_array("testme", $args);
}


$x = new X;
$x->key = 'value';

test1($x, array());

echo "x = {$x->key}\n";
?>
bkat’s picture

The reason I wasn't seeing the Warning on php 5.3.1 was because that system had
error_reporting = E_ALL & ~E_DEPRECATED in php.ini

E_DEPRECATED was added in php 5.3 so you can't use that on php 5.2.

sierrawayfarer’s picture

I have a real newby question. How do I apply the patch that is shown in #23?

sierrawayfarer’s picture

Never mind. I figured it out and it worked.

dom_b’s picture

It doesn't look like this is in Beta 4 but can somebody confirm this before I update to it? THanks!

cindyr’s picture

subscribing

Archnemysis’s picture

subscribing

henrykuo’s picture

After 3 weeks of hair pulling and tears of desparation, I finally found this page, applied the patch, and everything works perfect! I shall name my children after all that contributed to this patch, and will include you all in my will.

In all seriousness, I think there are a great many people who were barking up the wrong tree before me and along with me who need to somehow discover this patch. I migrated my site from a cheap cloud service to a VPS. For the most part, things that broke were easy to pinpoint and weed out...........until I ran up against the dreaded ImageCache not building images based on my presets.
So many people have come up against an ImageCache issue, and so many people are out there barking up this tree and screaming for a fix for the ImageCache module. It wasn't until I did extensive testing, digging into SSH and scientifically tested a great many scenarios that I finally came to a conclusion that it was not ImageCache's fault at all. It wasn't a folder permission problem. Not memory. Not ImageMagick. No wrong paths. Not the server setup incorrectly. It was in the end this ImageAPI module.

And, well, I don't really understand the details of why this fixed things, but I am extremely thankful for this. Hopefully some of the keywords in this message will point others in desparation here.

Berdir’s picture

+++ imageapi.module	6 Nov 2009 14:02:59 -0000
@@ -161,7 +161,7 @@ function imageapi_default_toolkit() {
-    array_unshift($params, $image);
+    array_unshift($params, &$image);

As others have pointed out, this is incorrect. Adding a & when calling functions is deprecated since PHP 5.0.

Instead, a possible fix would be to add a new line after array_unshift() that would look like:
$params[0] = &$image;

Note that both the array_unshift() (to add the element at the beginning and re-number the array indexes) and the by reference assignment are necessary.

Simply removing all & from the function definitions is a perfectly fine fix too, given that imageApi only supports PHP 5.2+

Powered by Dreditor.

old_dog’s picture

I should have come here earlier, however my head scratching led me to modify the line raising the error (165 in imageapi.module).
I added the & like so:

return call_user_func_array($function, &$params);

Seems to work OK for me.

Eggdude’s picture

Worked for me too thanks!

When I went from my testing environment to the server naturally I had to undo this fix as the server is still running an earlier version of PHP.

humanoc’s picture

The patch works but I don't understand, why the new beta10 doesn't include the patch yet.
I had to apply the patch again.

skozik’s picture

newbie here - can you explain how to apply the patch or include link where there are general patch instructions? thanx.

skozik’s picture

FOUND IT! : http://drupal.org/node/60818 general instructions for patching.

skozik’s picture

Welp, the patch in #23 doesn't work. There's a lot of back and forth here, and it's hard to tell what exactly is working for people. Can someone be so kind as to outline the "Final" answer?
thanks in advance.

davidwatson’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
581 bytes

Attached is a trivial patch based on #34, as that seems to be the most "correct" and simple solution that doesn't change the API. Tested on PHP 5.3, needs testing on <= 5.2.

Here's to hoping we can get this resolved once and for all.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Latest patch fixes this issue on PHP 5.3 and seems to be fully backwards compatible.

humanoc’s picture

You should open the .patch file with your favourite text editor.
Then remove the lines marked as - and add the ones as +.

marvil07’s picture

#41 works fine for me too

AdrianB’s picture

Subscribing.

TmaX’s picture

Patch from #41 worked for me just fine.

PieterDC’s picture

Patch from #41 worked for me just fine with both PHP 5.3.x and 5.2.x

Please add to the official release of the module.

b3liev3’s picture

It's the same with all the PHP 5.3 problems: "expected to be a reference" message.

I've got the same problem and solution with 5 different modules.

Btw, the patch works.

zilched’s picture

another confirmation that the patch works for php 5.3

ChrisRut’s picture

subscribing

jaxond’s picture

Patch in #41 works great here.

jantoine’s picture

Patch in #41 solves the issue. With all the positive reviews, please commit ASAP!

Cheers,

Antoine

osman’s picture

I confirm #41 works for me as well. Thanks c.ex

ImageAPI 6.x-1.6
PHP 5.3.2

Cyberwolf’s picture

Subscribing.

leprechau’s picture

#41 working like a champ...thank you

php 5.3.2
imagecache 6.x-2.0-beta10
imageapi 6.x-1.6

drewish’s picture

Sorry folks the pay job hasn't been leaving me much time. I'll spend some time on this issue queue today and review some patches.

jaimealsilva’s picture

subscribing

smthomas’s picture

subscribing

mr_hossein’s picture

i use from imageapi and take a problem.....
thumbnail image not display on gallery !!!!
what am i doing ?????

YK85’s picture

subscribing

deng17’s picture

#41 Works. Thanks

BeatnikDude’s picture

subscribing `(Òvó)

spacereactor’s picture

Can the ImageAPI team confirm #41 and add this to dev.

drewish’s picture

Status: Reviewed & tested by the community » Fixed

finally got this committed. i'll be checking a couple more patches and then rolling a new release.

Status: Fixed » Closed (fixed)

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

Mascher’s picture

Priority: Normal » Critical
Status: Closed (fixed) » Active

Module ImageAPI not work with php 5.3.3-pl1!

Error in log:
Parameter 2 to imageapi_gd_image_overlay() expected to be a reference, value given in file imageapi.module in line 166.

And i have error in apache log file:
Warning: Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in Unknown on line 0

Mascher’s picture

Issue tags: +PHP 5.3 compatibility

I found another team with some problems but in other modules - http://drupal.org/node/648950
Change tags.

Mascher’s picture

I try to use patch #14 buy this not take effect...
In log i see:
imagecopyresampled() expects parameter 5 to be long, string given in file /var/www/fantasy-portal.ru/htdocs/sites/all/modules/imageapi/imageapi_gd.module in line 99.

yan’s picture

Same as #67 with PHP 5.3.2-1ubuntu4.7.

yan’s picture

Seems to be solved by two small changes in bot imageapi.module and imagecache_canvasactions.module:

imageapi.module, line 161:

- function imageapi_toolkit_invoke($method, &$image, array $params = array()) {
+ function imageapi_toolkit_invoke($method, $image, array $params = array()) {

imagecache_canvasactions.module, line 170:

- function imageapi_gd_image_overlay(&$image, &$layer, $x, $y, $alpha = 100, $reverse = FALSE)
+ function imageapi_gd_image_overlay(&$image, $layer, $x, $y, $alpha = 100, $reverse = FALSE)
TwoD’s picture

Priority: Critical » Normal
Status: Active » Fixed

The error in #67 is NOT caused by this module.
It's the same problem, but caused by imagecache_actions passing around a second image "handle" as a value instead of a reference. It's not the job of imageapi to decide whether other module's arguments should be values or references (there's no way to tell which it should be), it isn't responsible for what's already in the $params argument. It's only responsible for making sure that the image object it adds to that array is a proper reference.
The problem has already been properly fixed in imagecache_action's 6.x-1.x branch, see #648950-12: Error with PHP 5.3.

The first change in #71 is wrong and would most likely break backwards compatibility with PHP < 5.3 as noted in #20 and elsewhere.

The same goes for the second change (the $layer is probably passed by reference for performance reasons, just a guess though since I can't find it being modified anywhere). Fixing it there would also not take care of all the other functions using imageapi_image_overlay(), so it would require changes to all of those functions, losing the pass-by-reference for earlier PHP versions.
It's better to fix it in imageapi_gd_overlay() as it is the function assembling the parameters before calling toolkit-specific implementations.

The error in #69 is not related to this issue at all. Somebody is trying to crop an image using an incorrect X position (A string is passed instead of a number).

Reverting issue status...

Status: Fixed » Closed (fixed)

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

gansbrest’s picture

FileSize
762 bytes

Hi,

Recently I've found similar problem with imageapi under php 5.3. It's similar to what TwoD said in #72

imageapi_gd_image_overlay(&$image, &$layer, $x, $y, $alpha = 100, $reverse = FALSE)

As you can see $layer attribute needs to be passed by reference and that will give you critical warning in 5.3 and image will not be generated.

One way to solve it is to modify imageapi_gd_image_overlay function and remove & from second attribute, but you would have to change imageapi_imagemagick_image_overlay same way to support both GD and IMAGEMAGICK. Another objection is that it may break in 5.2 since the functionality may expect param passed by reference.

Actually you can find the approach mentioned above in this thread http://drupal.org/node/789900 (#22)

My patch is based on the idea that no imageapi actions require more than 2 attributes passed by reference. If that's not the case, then we would have to create more complicated logic similar to this:

    if (function_exists($function)) {
    array_unshift($params, $image);
    $params[0] = &$image;
    $i = 1;
    foreach($params as $param) {
       if (!empty($param->toolkit)) {
          $param[$i] = &$param;
       }
    }
    return call_user_func_array($function, $params);
  }

This is just one variation of it. The attached patch is based on #41 from this thread but slightly altered to support overlay action.

We need some testing for 5.2 but that should work fine I guess.

pkiraly’s picture

FileSize
600 bytes

gansbrest's first change in not necessary, because that line is already in the code. Here's a solution for that.

PatchRanger’s picture

The patch in #74 doesn't work for me.
I'm using the latest dev-versions of ImafeAPI and Imagecache.

Trick that solved the problem : just enable "ImageAPI GD2".
May be there is some kind of dependency - but fact is fact : only enabling this module makes the photos appear to display.

Glad if it could help.

elielcezar’s picture

#12 worked for me

mikebrooks’s picture

For what it's worth...

We had the following error on our site:

warning: imagecopyresampled() expects parameter 5 to be long, string given in sites/all/modules/imageapi/imageapi_gd.module on line 98.

ImageAPI was at version 6.x-1.6.

PHP version was at 5.3.3-7+squeeze8

Updating to ImageAPI version 6.x-1.10 resolved the error.

- Mike

rwohleb’s picture

I updated to 6.x-1.10 and it fixed the majority of my PHP 5.3 issues. However, some presets continued to fail. I applied the patch in #75 to 6.x-1.10 and it fixed the remaining issues.

Danny Englander’s picture

Status: Closed (fixed) » Needs work

Sorry to reopen this, (and it looks like this has not been 100% resolved anyway). I was getting errors using ImageAPI 6.x-1.6 until I applied the patch in #74 and it resolved the issue of my imagecache images not (re)generating. This was a tough one to figure out. After applying the patch, my imagecache images regenerate fine. Note, I already had ImageAPI GD2 enabled but imagecache images did not regenerate until I applied the patch. Note I encountered this issue for the first time when I upgraded my server from PHP 5.2 to 5.3.

3soft’s picture

Assigned: Unassigned » 3soft

Solved the problem by installing new ImageAPI module - ver. 6.x-1.10

mrfelton’s picture

Status: Needs work » Needs review

Had this issue on a site that I just imported to Pantheon. Patch in #75 resolves. Thanks.

MiSc’s picture

Status: Needs review » Fixed

This is solved with upgrading to never version of ImageAPI.

Status: Fixed » Closed (fixed)
Issue tags: -PHP 5.3, -PHP 5.3 compatibility

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

cravecode’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review
FileSize
605 bytes

I ran into this issue with the imageapi_image_scale_and_crop function. Attached is a simple patch to remove the & from the $image parameter.

The patch should easily work on 6.x-1.x-dev, 6.x-1.9, and 6.x-1.10

tm01xx’s picture

Hi,

I am on Ubuntu, Apache2, PHP 5.3.10, Drupal 6.33, ImageAPI 6.x-1.9+4-dev and the problem still exists even after adding following lines:

array_unshift($params, &$image);
$params[0] = &$image;

So my workaround is:

if ($function == 'imageapi_gd_image_resize') {
  return imageapi_gd_image_resize($image, $params[1], $params[2]);
}

And it works so clearly, the PHP doesn't take $params[0] as object reference as we thought.

Regards,