php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71742 Arrays not readable by polyline
Submitted: 2016-03-08 13:38 UTC Modified: 2016-03-10 00:45 UTC
From: lee dot traynor at skeptic dot de Assigned: danack (profile)
Status: Closed Package: imagick (PECL)
PHP Version: 7.0.4 OS: Windows 7
Private report: No CVE-ID: None
 [2016-03-08 13:38 UTC] lee dot traynor at skeptic dot de
Description:
------------
---
From manual page: http://www.php.net/imagickdraw.polyline
---
polyline () and polygon () should accept arrays of the type:

[["x"=>0, "y"=>0], ["x"=>10, "y"=>10], ["x"=>20, "y"=>20], ...]

However if the array values are changed by array_walk () by reference, polyline () will not work in PHP 7, but does work in PHP <= 5.6.

Workaround is to call polyline on array_values ($array), instead of on $array itself, even if $array == array_values ($array) is true.

Test script:
---------------
foreach (range (0, 100) as $ln) $pb[] = ['x'=>2*$ln, 'y'=>pow ($ln, 2)];
array_walk ($pb, function (&$v){$v['y'] = 200 - $v['y'] / 50;});
// following line returns true:
var_dump ($pb == array_values ($pb));
$im = new Imagick ();
$im->newImage (200, 200, "white");
$draw = new ImagickDraw ();
$draw->setFillColor ("none");
$draw->setStrokeColor ("black");
//Fatal error in PHP 7, but not in PHP <= 5.6
//$draw->polyline ($pb);
//Works in PHP 7, even if $pb == array_values ($pb) is true
$draw->polyline (array_values ($pb));
$im->drawImage ($draw);
$im->writeImage (getcwd (). "/test.png");
echo "<img src=\"test.png\">";

Expected result:
----------------
Image with a parabola

Actual result:
--------------
Fatal error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-09 17:31 UTC] danack@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: danack
 [2016-03-09 17:31 UTC] danack@php.net
Thanks, this is fixed in version 3.4.1 which is being released now.

Windows binaries should be available as soon as the automated system builds them.
 [2016-03-10 00:45 UTC] danack@php.net
Actually....the windows build failed, so it will be released tomorrow.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 19:01:31 2024 UTC