PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Images » Image_Graph » Bug #6024

Undefined variable: parameters

Details

Submitted2005-11-21 13:29 UTC
Frompoweredbykrell at yahoo dot se
Assignednosey
StatusClosed
PackageImage_Graph
PHP Version4.3.11
OSLinux 2.4.20 i686 GNU/Linux
Roadmaps(Not assigned)

Comments

[2005-11-21 13:29 UTC] poweredbykrell at yahoo dot se

Description:
------------
Notice: Undefined variable: parameters in /www/pear/lib/Image/Graph/Common.php on line 248
Image_Graph 0.7.1 alpha

Warning: Cannot modify header information - headers already sent by (output started at /www/pear/lib/Image/Graph/Common.php:248) in /www/pear/lib/Image/Canvas.php

The foreach loop in the _error method appends data to an unassigned variable $parameters:

foreach ($params as $name => $key) {
if (isset($parameters)) {
$parameters .= ' ';
}
$parameters .= $name . '=' . $key; <--------
}

Test script:
---------------
function _error($text, $params = false, $error_code = IMAGE_GRAPH_ERROR_GENERIC)
{
$i = 0;
foreach ($params as $name => $key) {
if ($i > 0) {
$parameters .= ' ';
}
$parameters .= $name . '=' . $key;
$i++;
}
$error =& PEAR::raiseError(
$text .
($error_code != IMAGE_GRAPH_ERROR_GENERIC ? ' error:' . IMAGE_GRAPH_ERROR_GENERIC : '') .
(isset($parameters) ? ' parameters:[' . $parameters . ']' : '')
);
}

Expected result:
----------------
It will work as supposed without an undefined variable notice

Actual result:
--------------
Notice: Undefined variable: parameters in /www/pear/lib/Image/Graph/Common.php on line 248

[2005-11-21 13:40 UTC] poweredbykrell at yahoo dot se

This is a proposed fix

function _error($text, $params = false, $error_code = IMAGE_GRAPH_ERROR_GENERIC)
{
foreach ($params as $name => $key) {
if (isset($parameters)) {
$parameters .= ' ';
} else {
$parameters = '';
}
$parameters .= $name . '=' . $key;
}
$error =& PEAR::raiseError(
$text .
($error_code != IMAGE_GRAPH_ERROR_GENERIC ? ' error:' . IMAGE_GRAPH_ERROR_GENERIC : '') .
(isset($parameters) ? ' parameters:[' . $parameters . ']' : '')
);
}