ID:               41080
 User updated by:  rpeters+php at icomproductions dot ca
 Reported By:      rpeters+php at icomproductions dot ca
 Status:           Closed
 Bug Type:         Documentation problem
 Operating System: N/A
 PHP Version:      Irrelevant
 Assigned To:      bjori
 New Comment:

Perhaps I'm missing something. My test server is set up with PHP 5.1.6
(and perhaps this has become version dependant), and phpinfo reports:
GD Version: bundled (2.0.28 compatible)

I wrote the following code based on the current documentation on
ca.php.net. I'm unsure if your changes have propagated there as of yet,
but the modified date is today.

The following function will cause an exception if no third parameter is
specified. (This is a simplified version of the code that prompted this
bug report):

image_wrapper($type = "gif", $image = null, $filename = null)
{
  if($type == "gif")
    return imagegif($image, $filename);
  if($type == "wbmp")
    return imagewbmp($image, $filename);
  if($type == "png")
    return imagepng($image, $filename);
  if($type == "jpeg")
    return imagejpeg($image, $filename);
}

The current documentation (apart from that for imagepng) did not lead
me to believe that I was doing anything wrong, and the exception thrown
is not clear enough to understand what correction is required. This left
me grasping at straws, finally requiring a google search to find out
something that should be covered in the documentation.

To back up my assertion that the documentation needs to be specific in
this case, look at the number of php bugs reported due to developers
thinking the exception thrown by passing null as a second parameter was
a mistake in PHP itself.

The alternative, of course, is to make the php functions more
forgiving, but that has always been rejected in the aforementioned bug
reports.


Previous Comments:
------------------------------------------------------------------------

[2007-05-25 21:25:41] [EMAIL PROTECTED]

As I said. I fixed imagegif().
After reading the source more carefully NULL *IS* ok when libgd
provides the gdImageGifCtx() function, same applies for imagewbmp() when
compiled against libgd 1.5+.

imagegif() only has 2 arguments afaict, but does however not complain
if passed 4arguments.

imagejpeg() docs are correct, to skip it (but wishing to pass quality)
use null.

------------------------------------------------------------------------

[2007-05-25 20:25:40] rpeters+php at icomproductions dot ca

The doc experts are taken from ca.php.net, with modification dates of
the 24th or 25th of May.

imagegif, and imagewbmp both report:

The path to the saved file. If not set or NULL, the raw image stream
will be outputted directly.

imagejpeg reports:

To skip this argument in order to provide the quality parameter, use
NULL.

None of these pages have appropriate warnings over the use of NULL.
I suggest taking inspiration from the imagepng page, which states:

Note: NULL is invalid if the quality and filters arguments are not
used.

Again, I will note that imagegif is listed as having only 2 parameters
while other bug reports indicate it accepts 4. If it does only take 2,
then the documentation should refrain from specifying that filename can
be set as null in any circumstances. (There are no valid combinations of
two parameters where the second is null.)

------------------------------------------------------------------------

[2007-05-25 20:12:06] [EMAIL PROTECTED]

Fixed imagegif(), imagejpeg() was fix long time ago

------------------------------------------------------------------------

[2007-04-13 22:02:27] rpeters+php at icomproductions dot ca

Description:
------------
Documentation for imagegif and imagejpeg both incorrectly convey that
it is acceptable to pass null or an empty string as the second parameter
without specifying additional parameters.

It is also worth noting that imagegif docs state it only takes 2
parameters, while other bug report comments have indicated it takes 4.

Related: bug #38794

Reproduce code:
---------------
imagegif($imageData, '');

Expected result:
----------------
According to the docs, this should be acceptable, causing the image to
be outputted to the client.

Actual result:
--------------
It throws an exception trying to create a file with a null filename.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41080&edit=1

Reply via email to