Problem med modulen ImageAPI GD2

Events happening in the community are now at Drupal community events on www.drupal.org.
EllRod's picture

Har en Site med Drupal 6 installerad, den har blivit lite övergiven. Och nu har jag märkt att jag kan inte längre ladda upp "Slide images" som tidigare. Eftersom jag byggde inte den ursprungligen så hänger jag inte med vad som kan ha gått fel, på tanke att jag knapp jobbat med sajten.

Felmeddelande som jag får upp är följande:

warning: Parameter 1 to imageapi_gd_image_resize() expected to be a reference, value given in D:\apache\htdocs-creativelight.com\sites\all\modules\contribs\imageapi\imageapi.module on line 165.

kollat in raden enligt felmeddelandet:

/**
* Invokes the given method using the currently selected toolkit.
*
* @param $method
*   A string containing the method to invoke.
* @param $image
*   An image object returned by imageapi_image_open().
* @param $params
*   An optional array of parameters to pass to the toolkit method.
* @return
*   Mixed values (typically Boolean indicating successful operation).
*/
function imageapi_toolkit_invoke($method, &$image, array $params = array()) {
  $function = $image->toolkit . '_image_' . $method;
  if (function_exists($function)) {
    array_unshift($params, $image);
Line165:    return call_user_func_array($function, $params);
  }
  watchdog('imageapi', 'The selected image handling toolkit %toolkit can not correctly process %function.', array('%toolkit' => $image->toolkit, '%function' => $function), WATCHDOG_ERROR);
  return FALSE;
}

verka bli något form av miss, när funktionen efterfrågar en parameter.
Någon som känner igen problemet???

Comments

Troligen beror det på att du

pontus_nilsson's picture

Troligen beror det på att du kör PHP 5.3. Se denna issue.

//Pontus Nilsson, Digitalist

The problem is that in php

carlmcdade's picture

The problem is that in php 5.3 parameters need to be called by reference or call_user_func_array will quit. This is not the case with php 5.2 where it would just load the function anyway. The patches in the thread are not optimal since they use an array construct which could make things weird if the same solution is used elsewhere in Drupal. Since Drupal uses foreach() on objects and arrays a better solution is to assigned the reference directly to the loop element.

<?php


foreach($params as &$param) {
      
         
$param = $param;
      
}

if (
function_exists($function)) {
   
array_unshift($params, $image);
return
call_user_func_array($function, $params);
?>

This should make each parameter a reference to each orginal.
Notice: I have not tested this in any way!!!

Okay, I checked this out more

carlmcdade's picture

Okay, I checked this out more closely and I find it very irritating. Neither PHP or Drupal have any conventions on this which results in refactoring by PHP version. In PHP 5.3:

Referenced variables in param_arr are passed to the function by reference, regardless of whether the function expects the respective parameter to be passed by reference. This form of call-time pass by reference does not emit a deprecation notice, but it is nonetheless deprecated, and will most likely be removed in the next version of PHP. Furthermore, this does not apply to internal functions, for which the function signature is honored. Passing by value when the function expects a parameter by reference results in a warning and having call_user_func() return FALSE (does not apply if the passed value has a reference count = 1).

But in previous versions using the ampersand is okay:

<?php
error_reporting
(E_ALL);
function
increment(&$var)
{
   
$var++;
}

$a = 0;
call_user_func('increment', $a);
echo
$a."\n";

call_user_func_array('increment', array(&$a)); // You can use this instead before PHP 5.3
echo $a."\n";
?>

And of course if Drupal used proper OO this problem might not exist :(

Sweden

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: