Bug #69379 [NEW]: zend_parse_parameters and reference, flag is reversed
| From: | danack@php.net | Date: | Sun, 05 Apr 2015 15:07:11 +0000 |
| Subject: | Bug #69379 [NEW]: zend_parse_parameters and reference, flag is reversed | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-191837@lists.php.net to get a copy of this message | ||
From: danack
Operating system: N/A
PHP version: master-Git-2015-04-05 (Git)
Package: Scripting Engine problem
Bug Type: Bug
Bug description:zend_parse_parameters and reference, flag is reversed
Description:
------------
It seems that in PHP7 the '/' flag has had it's meaning reversed. It is
documented as:
"'/' - This indicates that the preceding parameter should be separated
from the calling parameter, in case you wish to modify it locally in the
function without modifying the original calling parameter."
i.e. if you want a function to accept a parameter by reference you
should _not_ use this flag, so that when you set the variable inside the
function, the new value is seen outside by any reference to the variable
outside the function.
However it is now _required_ to set the '/' flag to pass a variable by
reference.
Example code from -
https://github.com/mkoppanen/imagick/blob/phpseven/imagick_class.c#L11636
This code works to set the parameter in 5.x:
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|zz", &reference_obj,
php_imagick_sc_entry, &z_best_match_offset, &z_similarity);
if (z_similarity) {
ZVAL_DOUBLE(z_similarity, similarity);
}
That code needs to be changed to this in 7:
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|z/z/",
&reference_obj, php_imagick_sc_entry, &z_best_match_offset,
&z_similarity);
if (z_similarity) {
ZVAL_DOUBLE(z_similarity, similarity);
}
It appears this change was done in this commit:
https://github.com/php/php-src/commit/c1965f58d4dd3970912dcd6a63ccd5860bae1a97
Test script:
---------------
<?php
$imagick = new \Imagick();
$imagick->newPseudoImage(640, 480, "magick:logo");
$imagick2 = clone $imagick;
$imagick2->cropimage(40, 40, 250, 110);
$imagick2->vignetteimage(0, 1, 3, 3);
$similarity = 'not set';
$bestMatch = 'not set';
$comparison = $imagick->subImageMatch($imagick2, $bestMatch,
$similarity);
var_dump($similarity);
Expected result:
----------------
float(0.90996121310752)
Actual result:
--------------
string(7) "not set"
--
Edit bug report at https://bugs.php.net/bug.php?id=69379&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69379&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69379&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69379&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69379&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69379&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69379&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69379&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69379&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69379&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69379&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69379&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69379&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69379&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69379&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69379&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69379&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69379&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69379&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69379&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69379&r=mysqlcfg