Skip to content

Commit 8d6e377

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Update NEWS for the intl reference fixes Fix reference handling of IntlTimeZone::getCanonicalID/intltz_get_canonical_id Fix reference handling of grapheme_extract() Fix numfmt_parse_currency() reference handling
2 parents d991215 + 9c555f5 commit 8d6e377

7 files changed

+68
-20
lines changed

NEWS

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ PHP NEWS
88
correct) (JiriJozif).
99

1010
- Intl:
11-
. datefmt_parse/datefmt_localtime references type system fixes. (nielsdos)
12-
. Fix IntlDateFormatter::parseToCalendar() reference type system breaks.
13-
(nielsdos)
11+
. Fix various reference issues. (nielsdos)
1412

1513
- Opcache:
1614
. Fixed bug GH-18417 (Windows SHM reattachment fails when increasing

ext/intl/formatter/formatter_parse.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ PHP_FUNCTION( numfmt_parse_currency )
135135
FORMATTER_METHOD_INIT_VARS;
136136

137137
/* Parse parameters. */
138-
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz/|z!",
138+
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz|z!",
139139
&object, NumberFormatter_ce_ptr, &str, &str_len, &zcurrency, &zposition ) == FAILURE )
140140
{
141141
RETURN_THROWS();
@@ -165,8 +165,7 @@ PHP_FUNCTION( numfmt_parse_currency )
165165
/* Convert parsed currency to UTF-8 and pass it back to caller. */
166166
u8str = intl_convert_utf16_to_utf8(currency, u_strlen(currency), &INTL_DATA_ERROR_CODE(nfo));
167167
INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-8 failed" );
168-
zval_ptr_dtor( zcurrency );
169-
ZVAL_NEW_STR(zcurrency, u8str);
168+
ZEND_TRY_ASSIGN_REF_NEW_STR(zcurrency, u8str);
170169

171170
RETVAL_DOUBLE( number );
172171
}

ext/intl/grapheme/grapheme_string.c

+6-11
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,10 @@ PHP_FUNCTION(grapheme_extract)
734734
}
735735

736736
if ( NULL != next ) {
737-
if ( !Z_ISREF_P(next) ) {
738-
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
739-
"grapheme_extract: 'next' was not passed by reference", 0 );
740-
RETURN_FALSE;
741-
} else {
742-
ZVAL_DEREF(next);
743-
/* initialize next */
744-
zval_ptr_dtor(next);
745-
ZVAL_LONG(next, lstart);
737+
ZEND_ASSERT(Z_ISREF_P(next));
738+
ZEND_TRY_ASSIGN_REF_LONG(next, lstart);
739+
if (UNEXPECTED(EG(exception))) {
740+
RETURN_THROWS();
746741
}
747742
}
748743

@@ -799,7 +794,7 @@ PHP_FUNCTION(grapheme_extract)
799794
if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) {
800795
size_t nsize = MIN(size, str_len);
801796
if ( NULL != next ) {
802-
ZVAL_LONG(next, start+nsize);
797+
ZEND_TRY_ASSIGN_REF_LONG(next, start + nsize);
803798
}
804799
RETURN_STRINGL(pstr, nsize);
805800
}
@@ -833,7 +828,7 @@ PHP_FUNCTION(grapheme_extract)
833828
ubrk_close(bi);
834829

835830
if ( NULL != next ) {
836-
ZVAL_LONG(next, start+ret_pos);
831+
ZEND_TRY_ASSIGN_REF_LONG(next, start + ret_pos);
837832
}
838833

839834
RETURN_STRINGL(((char *)pstr), ret_pos);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
grapheme_extract() references handling
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
class Test {
8+
public string $prop = "a";
9+
}
10+
$test = new Test;
11+
$next =& $test->prop;
12+
grapheme_extract("test", 4, next: $next);
13+
var_dump($test);
14+
?>
15+
--EXPECT--
16+
object(Test)#1 (1) {
17+
["prop"]=>
18+
&string(1) "4"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
IntlTimeZone::getCanonicalID: refs test
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
class Test {
8+
public string $prop = "a";
9+
}
10+
$test = new Test;
11+
$ref =& $test->prop;
12+
print_R(intltz_get_canonical_id('Portugal', $ref));
13+
var_dump($test);
14+
?>
15+
--EXPECT--
16+
Europe/Lisbonobject(Test)#1 (1) {
17+
["prop"]=>
18+
&string(1) "1"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
numfmt_parse_currency() reference handling
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
class Test {
8+
public int $prop = 1;
9+
}
10+
$test = new Test;
11+
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
12+
$num = "1\xc2\xa0$";
13+
try {
14+
numfmt_parse_currency($fmt, $num, $test->prop);
15+
} catch (TypeError $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
?>
19+
--EXPECT--
20+
Cannot assign string to reference held by property Test::$prop of type int

ext/intl/timezone/timezone_methods.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id)
286286
RETVAL_NEW_STR(u8str);
287287

288288
if (is_systemid) { /* by-ref argument passed */
289-
ZVAL_DEREF(is_systemid);
290-
zval_ptr_dtor(is_systemid);
291-
ZVAL_BOOL(is_systemid, isSystemID);
289+
ZEND_TRY_ASSIGN_REF_BOOL(is_systemid, isSystemID);
292290
}
293291
}
294292

0 commit comments

Comments
 (0)