Bug #69379 [Com]: zend_parse_parameters and reference, flag is reversed
| From: | danack@php.net | Date: | Sun, 05 Apr 2015 15:25:41 +0000 |
| Subject: | Bug #69379 [Com]: zend_parse_parameters and reference, flag is reversed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191839@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69379&edit=1
ID: 69379
Comment by: danack@php.net
Reported by: danack@php.net
Summary: zend_parse_parameters and reference, flag is
reversed
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: N/A
PHP Version: master-Git-2015-04-05 (Git)
Block user comment: N
Private report: N
New Comment:
I guess it is documented in the upgrading guide - https://wiki.php.net/phpng-upgrading
"arguments passed by reference should be assigned into the referenced value. It's possible
to separte such arguments, to get referenced value at first place."
So that really means, if your function wants to accept a parameter by reference it must change from
'z' to 'z/' ?
Previous Comments:
------------------------------------------------------------------------
[2015-04-05 15:15:39] nikic@php.net
"/" means "separate" and indeed in PHP 7 it is required in all cases where you
want to modify a passed zval, even if it's a reference. But I'm not sure I get what the
bug report is about, is this a documentation problem? If so, could you please point to which docs
you're quoting here?
------------------------------------------------------------------------
[2015-04-05 15:07:10] danack@php.net
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 this bug report at https://bugs.php.net/bug.php?id=69379&edit=1