Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.5

Bug #5989 Factory method does not allow no driver to be specified
Submitted: 2005-11-16 17:46 UTC
From: gauthierm Assigned: jausions
Status: Closed Package: Image_Transform
PHP Version: 5.0.5 OS: Linux
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 40 - 26 = ?

 
 [2005-11-16 17:46 UTC] gauthierm
Description: ------------ The factory method says in the documentation that if no driver is specified then drivers are tried in the order Imagick2, GD and Imlib. The factory method's $driver parameter does not have a default value so it is impossible to not specify a driver. Test script: --------------- $transformer = Image_Transform::factory(); Here is a proposed patch. It also beings the method in line with PEAR variable naming standards: --- Transform.php 2005-11-16 13:34:12.396174099 -0400 +++ Transform.php.old 2005-11-16 13:34:43.491133540 -0400 @@ -196,17 +196,16 @@ * @see PEAR::isError() * @see Image_Transform::setOption() */ - function &factory($driver = '') + function &factory($driver) { - if ($driver == '') { - $extensions = array( + if ('' == $driver) { + $aExtensions = array( 'imagick' => 'Imagick2', 'gd' => 'GD', 'imlib' => 'Imlib'); - - foreach ($extensions as $ext => $ext_driver) { - if (PEAR::loadExtension($ext)) { - $driver = $ext_driver; + foreach ($aExtensions as $sExt => $sDriver) { + if (PEAR::loadExtension($sExt)) { + $driver = $sDriver; break; } } Expected result: ---------------- An image transformer to be created with one of the available extensions. Actual result: -------------- Warning: Missing argument 1 for Image_Transform::factory() in /usr/lib/php/Image/Transform.php on line 199

Comments

 [2005-11-16 17:49 UTC] gauthierm
Sorry, I diffed that backwards. Here is the correct patch: --- Transform.php.old 2005-11-16 13:34:43.491133540 -0400 +++ Transform.php 2005-11-16 13:34:12.396174099 -0400 @@ -196,16 +196,17 @@ * @see PEAR::isError() * @see Image_Transform::setOption() */ - function &factory($driver) + function &factory($driver = '') { - if ('' == $driver) { - $aExtensions = array( + if ($driver == '') { + $extensions = array( 'imagick' => 'Imagick2', 'gd' => 'GD', 'imlib' => 'Imlib'); - foreach ($aExtensions as $sExt => $sDriver) { - if (PEAR::loadExtension($sExt)) { - $driver = $sDriver; + + foreach ($extensions as $ext => $ext_driver) { + if (PEAR::loadExtension($ext)) { + $driver = $ext_driver; break; } }
 [2005-11-16 18:19 UTC] nrf
Here's a patch that applies cleanly to CVS head: http://worksintheory.org/files/pear/ImageTransform-factory-20051116.diff
 [2006-03-01 17:40 UTC] jausions
Thank you for taking the time to report a problem with the package. This problem may have been already fixed by a previous change that is in the CVS of the package. Please log into CVS with: cvs -d :pserver:cvsread@cvs.php.net:/repository login and check out the CVS repository of this package and upgrade cvs -d :pserver:cvsread@cvs.php.net:/repository co pear/Image_Transform pear upgrade pear/Image_Transform/package2.xml or pear upgrade pear/Image_Transform/package.xml If you are able to reproduce the bug with the latest CVS, please change the status back to "Open". Again, thank you for your continued support of PEAR.
 [2006-03-01 18:48 UTC] gauthierm
We are unable to reproduce this bug using 1.34 from CVS. Marking as closed.
 [2006-03-01 18:53 UTC] pajoye
summary changed, keep it please
 [2006-03-01 19:04 UTC] gauthierm
Changed back summary. Submitted http://pear.php.net/bugs/bug.php?id=6981 explaining why it got changed in the first place.