mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix reference handling of grapheme_extract()
Closes GH-18471.
This commit is contained in:
parent
e3cac07a9b
commit
e3105f5f1e
2 changed files with 25 additions and 11 deletions
|
@ -711,15 +711,10 @@ PHP_FUNCTION(grapheme_extract)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( NULL != next ) {
|
if ( NULL != next ) {
|
||||||
if ( !Z_ISREF_P(next) ) {
|
ZEND_ASSERT(Z_ISREF_P(next));
|
||||||
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
|
ZEND_TRY_ASSIGN_REF_LONG(next, lstart);
|
||||||
"grapheme_extract: 'next' was not passed by reference", 0 );
|
if (UNEXPECTED(EG(exception))) {
|
||||||
RETURN_FALSE;
|
RETURN_THROWS();
|
||||||
} else {
|
|
||||||
ZVAL_DEREF(next);
|
|
||||||
/* initialize next */
|
|
||||||
zval_ptr_dtor(next);
|
|
||||||
ZVAL_LONG(next, lstart);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,7 +771,7 @@ PHP_FUNCTION(grapheme_extract)
|
||||||
if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) {
|
if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) {
|
||||||
size_t nsize = MIN(size, str_len);
|
size_t nsize = MIN(size, str_len);
|
||||||
if ( NULL != next ) {
|
if ( NULL != next ) {
|
||||||
ZVAL_LONG(next, start+nsize);
|
ZEND_TRY_ASSIGN_REF_LONG(next, start + nsize);
|
||||||
}
|
}
|
||||||
RETURN_STRINGL(pstr, nsize);
|
RETURN_STRINGL(pstr, nsize);
|
||||||
}
|
}
|
||||||
|
@ -810,7 +805,7 @@ PHP_FUNCTION(grapheme_extract)
|
||||||
ubrk_close(bi);
|
ubrk_close(bi);
|
||||||
|
|
||||||
if ( NULL != next ) {
|
if ( NULL != next ) {
|
||||||
ZVAL_LONG(next, start+ret_pos);
|
ZEND_TRY_ASSIGN_REF_LONG(next, start + ret_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_STRINGL(((char *)pstr), ret_pos);
|
RETURN_STRINGL(((char *)pstr), ret_pos);
|
||||||
|
|
19
ext/intl/tests/grapheme_extract_references.phpt
Normal file
19
ext/intl/tests/grapheme_extract_references.phpt
Normal 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"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue