Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#86 | imageapi-php_5_3_reference_error-540486-86.patch | 605 bytes | cravecode |
#75 | imageapi-5334254-75.patch | 600 bytes | pkiraly |
#74 | imageapi-540486-74.patch | 762 bytes | gansbrest |
#41 | imageapi-540486-41.patch | 581 bytes | davidwatson |
#23 | imageapi_540486.patch | 674 bytes | jcnventura |
Comments
Comment #1
drasgardian CreditAttribution: drasgardian commentedI 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
inside imageapi_gd.module
Comment #2
drewish CreditAttribution: drewish commentedyeah 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().
Comment #3
jbrauer CreditAttribution: jbrauer commentedComment #4
eforth CreditAttribution: eforth commentedThis solution worked for me as well
Comment #5
eforth CreditAttribution: eforth commentedThis 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
Comment #6
drewish CreditAttribution: drewish commentedto be clear it works fine with our with out them it's just throwing warnings.
Comment #7
NelM CreditAttribution: NelM commentedthanks 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!
Comment #8
infojunkieWorked for me too! Thanks.
Comment #9
jdelaune CreditAttribution: jdelaune commentedWorked so well I made it into a patch...
Comment #10
VM CreditAttribution: VM commentedpatches 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.
Comment #11
szb100 CreditAttribution: szb100 commentedsubscribing
Comment #12
nicholasThompsonThe other way is to fix the ImageAPI.module...
Adding this fixed the problem for me.
Comment #13
willazilla CreditAttribution: willazilla commentedUnless 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!!
Comment #14
drewish CreditAttribution: drewish commentedwe need to hit the imagemagick code too. i incorporated nicholasThompson's change since it seemed to make sense.
Comment #15
mairav CreditAttribution: mairav commentedThanks! It worked for me too with the patch given in #14 by drewish. I hope this can be added to the dev version.
Comment #16
dom_b CreditAttribution: dom_b commentedwarning: Parameter 1 to imageapi_gd_image_resize() expected to be a reference
same error with lots of modules.
Comment #17
drewish CreditAttribution: drewish commenteddom_b, was that after applying the patch?
Comment #18
dom_b CreditAttribution: dom_b commentedi'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!
Comment #19
Deciphered CreditAttribution: Deciphered commentedPatch worked for me.
Comment #20
Deciphered CreditAttribution: Deciphered commentedI take that back, while the patch does fix issues with PHP 5.3, it creates issues for < PHP 5.3.
Needs work.
Cheers,
Deciphered.
Comment #21
jcnventura CreditAttribution: jcnventura commentedLooking 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
Comment #22
p0pemar1naru CreditAttribution: p0pemar1naru commentedI think Deciphered #20 is right. Less headbanging to just remove the "&" as a quick and dirty solution.
Nick
Comment #23
jcnventura CreditAttribution: jcnventura commentedAdding 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.
Comment #24
vannus CreditAttribution: vannus commentedwith 6.x-1.6 thumbnails where broken for me with php 5.3.0.
#23 patch with & works fine, glad it was here.
Comment #25
jcnventura CreditAttribution: jcnventura commentedI 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
Comment #26
bkat CreditAttribution: bkat commentedActually 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:
Comment #27
bkat CreditAttribution: bkat commentedThe 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.
Comment #28
sierrawayfarer CreditAttribution: sierrawayfarer commentedI have a real newby question. How do I apply the patch that is shown in #23?
Comment #29
sierrawayfarer CreditAttribution: sierrawayfarer commentedNever mind. I figured it out and it worked.
Comment #30
dom_b CreditAttribution: dom_b commentedIt doesn't look like this is in Beta 4 but can somebody confirm this before I update to it? THanks!
Comment #31
cindyr CreditAttribution: cindyr commentedsubscribing
Comment #32
Archnemysis CreditAttribution: Archnemysis commentedsubscribing
Comment #33
henrykuo CreditAttribution: henrykuo commentedAfter 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.
Comment #34
BerdirAs 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.
Comment #35
old_dog CreditAttribution: old_dog commentedI 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.
Comment #36
Anonymous (not verified) CreditAttribution: Anonymous commentedWorked 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.
Comment #37
humanoc CreditAttribution: humanoc commentedThe patch works but I don't understand, why the new beta10 doesn't include the patch yet.
I had to apply the patch again.
Comment #38
skozik CreditAttribution: skozik commentednewbie here - can you explain how to apply the patch or include link where there are general patch instructions? thanx.
Comment #39
skozik CreditAttribution: skozik commentedFOUND IT! : http://drupal.org/node/60818 general instructions for patching.
Comment #40
skozik CreditAttribution: skozik commentedWelp, 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.
Comment #41
davidwatson CreditAttribution: davidwatson commentedAttached 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.
Comment #42
sunLatest patch fixes this issue on PHP 5.3 and seems to be fully backwards compatible.
Comment #43
humanoc CreditAttribution: humanoc commentedYou should open the .patch file with your favourite text editor.
Then remove the lines marked as - and add the ones as +.
Comment #44
marvil07 CreditAttribution: marvil07 commented#41 works fine for me too
Comment #45
AdrianB CreditAttribution: AdrianB commentedSubscribing.
Comment #46
TmaX-2 CreditAttribution: TmaX-2 commentedPatch from #41 worked for me just fine.
Comment #47
PieterDCPatch 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.
Comment #48
b3liev3 CreditAttribution: b3liev3 commentedIt'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.
Comment #49
zilched CreditAttribution: zilched commentedanother confirmation that the patch works for php 5.3
Comment #50
ChrisRut CreditAttribution: ChrisRut commentedsubscribing
Comment #51
jaxond CreditAttribution: jaxond commentedPatch in #41 works great here.
Comment #52
jantoine CreditAttribution: jantoine commentedPatch in #41 solves the issue. With all the positive reviews, please commit ASAP!
Cheers,
Antoine
Comment #53
osmanI confirm #41 works for me as well. Thanks c.ex
ImageAPI 6.x-1.6
PHP 5.3.2
Comment #54
Cyberwolf CreditAttribution: Cyberwolf commentedSubscribing.
Comment #55
leprechau CreditAttribution: leprechau commented#41 working like a champ...thank you
php 5.3.2
imagecache 6.x-2.0-beta10
imageapi 6.x-1.6
Comment #56
drewish CreditAttribution: drewish commentedSorry 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.
Comment #57
jaimealsilva CreditAttribution: jaimealsilva commentedsubscribing
Comment #59
codekarate CreditAttribution: codekarate commentedsubscribing
Comment #60
mr_hossein CreditAttribution: mr_hossein commentedi use from imageapi and take a problem.....
thumbnail image not display on gallery !!!!
what am i doing ?????
Comment #61
YK85 CreditAttribution: YK85 commentedsubscribing
Comment #62
deng17 CreditAttribution: deng17 commented#41 Works. Thanks
Comment #63
BeatnikDude CreditAttribution: BeatnikDude commentedsubscribing `(Òvó)
Comment #64
spacereactor CreditAttribution: spacereactor commentedCan the ImageAPI team confirm #41 and add this to dev.
Comment #65
drewish CreditAttribution: drewish commentedfinally got this committed. i'll be checking a couple more patches and then rolling a new release.
Comment #67
Mascher CreditAttribution: Mascher commentedModule 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
Comment #68
Mascher CreditAttribution: Mascher commentedI found another team with some problems but in other modules - http://drupal.org/node/648950
Change tags.
Comment #69
Mascher CreditAttribution: Mascher commentedI 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.
Comment #70
yan CreditAttribution: yan commentedSame as #67 with PHP 5.3.2-1ubuntu4.7.
Comment #71
yan CreditAttribution: yan commentedSeems to be solved by two small changes in bot imageapi.module and imagecache_canvasactions.module:
imageapi.module, line 161:
imagecache_canvasactions.module, line 170:
Comment #72
TwoDThe 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...
Comment #74
gansbrest CreditAttribution: gansbrest commentedHi,
Recently I've found similar problem with imageapi under php 5.3. It's similar to what TwoD said in #72
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:
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.
Comment #75
pkiraly CreditAttribution: pkiraly commentedgansbrest's first change in not necessary, because that line is already in the code. Here's a solution for that.
Comment #76
PatchRanger CreditAttribution: PatchRanger commentedThe 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.
Comment #77
elielcezar CreditAttribution: elielcezar commented#12 worked for me
Comment #78
mikebrooks CreditAttribution: mikebrooks commentedFor 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
Comment #79
rwohlebI 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.
Comment #80
Danny EnglanderSorry 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.
Comment #81
3soft CreditAttribution: 3soft commentedSolved the problem by installing new ImageAPI module - ver. 6.x-1.10
Comment #82
mrfelton CreditAttribution: mrfelton commentedHad this issue on a site that I just imported to Pantheon. Patch in #75 resolves. Thanks.
Comment #83
MiSc CreditAttribution: MiSc commentedThis is solved with upgrading to never version of ImageAPI.
Comment #86
cravecode CreditAttribution: cravecode commentedI 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
, and6.x-1.10
Comment #87
tm01xx CreditAttribution: tm01xx commentedHi,
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:
So my workaround is:
And it works so clearly, the PHP doesn't take $params[0] as object reference as we thought.
Regards,