1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

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
This commit is contained in:
Niels Dossche
2025-05-01 10:42:25 +02:00
7 changed files with 68 additions and 20 deletions

4
NEWS
View File

@@ -8,9 +8,7 @@ PHP NEWS
correct) (JiriJozif).
- Intl:
. datefmt_parse/datefmt_localtime references type system fixes. (nielsdos)
. Fix IntlDateFormatter::parseToCalendar() reference type system breaks.
(nielsdos)
. Fix various reference issues. (nielsdos)
- Opcache:
. Fixed bug GH-18417 (Windows SHM reattachment fails when increasing

View File

@@ -135,7 +135,7 @@ PHP_FUNCTION( numfmt_parse_currency )
FORMATTER_METHOD_INIT_VARS;
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz/|z!",
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz|z!",
&object, NumberFormatter_ce_ptr, &str, &str_len, &zcurrency, &zposition ) == FAILURE )
{
RETURN_THROWS();
@@ -165,8 +165,7 @@ PHP_FUNCTION( numfmt_parse_currency )
/* Convert parsed currency to UTF-8 and pass it back to caller. */
u8str = intl_convert_utf16_to_utf8(currency, u_strlen(currency), &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-8 failed" );
zval_ptr_dtor( zcurrency );
ZVAL_NEW_STR(zcurrency, u8str);
ZEND_TRY_ASSIGN_REF_NEW_STR(zcurrency, u8str);
RETVAL_DOUBLE( number );
}

View File

@@ -734,15 +734,10 @@ PHP_FUNCTION(grapheme_extract)
}
if ( NULL != next ) {
if ( !Z_ISREF_P(next) ) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"grapheme_extract: 'next' was not passed by reference", 0 );
RETURN_FALSE;
} else {
ZVAL_DEREF(next);
/* initialize next */
zval_ptr_dtor(next);
ZVAL_LONG(next, lstart);
ZEND_ASSERT(Z_ISREF_P(next));
ZEND_TRY_ASSIGN_REF_LONG(next, lstart);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}
}
@@ -799,7 +794,7 @@ PHP_FUNCTION(grapheme_extract)
if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) {
size_t nsize = MIN(size, str_len);
if ( NULL != next ) {
ZVAL_LONG(next, start+nsize);
ZEND_TRY_ASSIGN_REF_LONG(next, start + nsize);
}
RETURN_STRINGL(pstr, nsize);
}
@@ -833,7 +828,7 @@ PHP_FUNCTION(grapheme_extract)
ubrk_close(bi);
if ( NULL != next ) {
ZVAL_LONG(next, start+ret_pos);
ZEND_TRY_ASSIGN_REF_LONG(next, start + ret_pos);
}
RETURN_STRINGL(((char *)pstr), ret_pos);

View File

@@ -0,0 +1,19 @@
--TEST--
grapheme_extract() references handling
--EXTENSIONS--
intl
--FILE--
<?php
class Test {
public string $prop = "a";
}
$test = new Test;
$next =& $test->prop;
grapheme_extract("test", 4, next: $next);
var_dump($test);
?>
--EXPECT--
object(Test)#1 (1) {
["prop"]=>
&string(1) "4"
}

View File

@@ -0,0 +1,19 @@
--TEST--
IntlTimeZone::getCanonicalID: refs test
--EXTENSIONS--
intl
--FILE--
<?php
class Test {
public string $prop = "a";
}
$test = new Test;
$ref =& $test->prop;
print_R(intltz_get_canonical_id('Portugal', $ref));
var_dump($test);
?>
--EXPECT--
Europe/Lisbonobject(Test)#1 (1) {
["prop"]=>
&string(1) "1"
}

View File

@@ -0,0 +1,20 @@
--TEST--
numfmt_parse_currency() reference handling
--EXTENSIONS--
intl
--FILE--
<?php
class Test {
public int $prop = 1;
}
$test = new Test;
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
$num = "1\xc2\xa0$";
try {
numfmt_parse_currency($fmt, $num, $test->prop);
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot assign string to reference held by property Test::$prop of type int

View File

@@ -286,9 +286,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id)
RETVAL_NEW_STR(u8str);
if (is_systemid) { /* by-ref argument passed */
ZVAL_DEREF(is_systemid);
zval_ptr_dtor(is_systemid);
ZVAL_BOOL(is_systemid, isSystemID);
ZEND_TRY_ASSIGN_REF_BOOL(is_systemid, isSystemID);
}
}