mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00

* ext/pcre: Refactor php_pcre_replace_func_impl() to not rely on an FCI * ext/pcre: Refactor populate_subpat_array() to take subject as a HashTable* This makes the assumption the zval is always an array explicit * ext/pcre: Refactor php_pcre_replace_func_impl() We don't need the FCI any more, and we always have the subject as a zend_string. * ext/pcre: Refactor php_pcre_replace_func() We don't need the FCI any more * ext/pcre: Refactor php_replace_in_subject_func() We don't need the FCI any more Make the Hashtable param const Throw exception on non string entries * ext/pcre: Refactor preg_replace_func_impl() We don't need the FCI anymore Make the Hashtable params const Rename function to indicate it is a PHP pcre function * ext/pcre: Add trampoline tests for preg_replace_callback(_array)() * ext/pcre: Handle trampolines properly for preg_replace_callback(_array)() * Revert FCI passing removal
133 lines
3.7 KiB
PHP
133 lines
3.7 KiB
PHP
--TEST--
|
|
preg_replace_callback() with a trampoline
|
|
--FILE--
|
|
<?php
|
|
|
|
class TrampolineTest {
|
|
public function __call(string $name, array $arguments): string {
|
|
echo 'Trampoline for ', $name, PHP_EOL;
|
|
if ($name === 'trampolineThrow') {
|
|
throw new Exception('boo');
|
|
}
|
|
return "'" . $arguments[0][0] . "'";
|
|
}
|
|
}
|
|
$o = new TrampolineTest();
|
|
$callback = [$o, 'trampoline'];
|
|
$callbackThrow = [$o, 'trampolineThrow'];
|
|
|
|
$regexesToTest = [
|
|
[
|
|
'@\b\w{1,2}\b@',
|
|
'~\A.~',
|
|
],
|
|
'@\b\w{1,2}\b@',
|
|
[
|
|
new stdClass(),
|
|
],
|
|
];
|
|
|
|
$subjectsToTest = [
|
|
[
|
|
'a b3 bcd',
|
|
'v' => 'aksfjk',
|
|
12 => 'aa bb',
|
|
['xyz'],
|
|
],
|
|
'a b3 bcd',
|
|
[
|
|
new stdClass(),
|
|
],
|
|
new stdClass(),
|
|
];
|
|
|
|
foreach ([$callback, $callbackThrow] as $fn) {
|
|
foreach ($regexesToTest as $regex) {
|
|
foreach ($subjectsToTest as $subject) {
|
|
try {
|
|
$matches = preg_replace_callback($regex, $fn, $subject);
|
|
var_dump($matches);
|
|
} catch (Throwable $e) {
|
|
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
--EXPECTF--
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
|
|
Warning: Array to string conversion in %s on line %d
|
|
Trampoline for trampoline
|
|
array(4) {
|
|
[0]=>
|
|
string(14) "'''a' 'b3' bcd"
|
|
["v"]=>
|
|
string(8) "'a'ksfjk"
|
|
[12]=>
|
|
string(11) "'''aa' 'bb'"
|
|
[13]=>
|
|
string(7) "'A'rray"
|
|
}
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
string(14) "'''a' 'b3' bcd"
|
|
Error: Object of class stdClass could not be converted to string
|
|
TypeError: preg_replace_callback(): Argument #3 ($subject) must be of type array|string, stdClass given
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
|
|
Warning: Array to string conversion in %s on line %d
|
|
array(4) {
|
|
[0]=>
|
|
string(12) "'a' 'b3' bcd"
|
|
["v"]=>
|
|
string(6) "aksfjk"
|
|
[12]=>
|
|
string(9) "'aa' 'bb'"
|
|
[13]=>
|
|
string(5) "Array"
|
|
}
|
|
Trampoline for trampoline
|
|
Trampoline for trampoline
|
|
string(12) "'a' 'b3' bcd"
|
|
Error: Object of class stdClass could not be converted to string
|
|
TypeError: preg_replace_callback(): Argument #3 ($subject) must be of type array|string, stdClass given
|
|
|
|
Warning: Array to string conversion in %s on line %d
|
|
Error: Object of class stdClass could not be converted to string
|
|
Error: Object of class stdClass could not be converted to string
|
|
Error: Object of class stdClass could not be converted to string
|
|
TypeError: preg_replace_callback(): Argument #3 ($subject) must be of type array|string, stdClass given
|
|
Trampoline for trampolineThrow
|
|
|
|
Warning: Array to string conversion in %s on line %d
|
|
Exception: boo
|
|
Trampoline for trampolineThrow
|
|
Exception: boo
|
|
Error: Object of class stdClass could not be converted to string
|
|
TypeError: preg_replace_callback(): Argument #3 ($subject) must be of type array|string, stdClass given
|
|
Trampoline for trampolineThrow
|
|
|
|
Warning: Array to string conversion in %s on line %d
|
|
Exception: boo
|
|
Trampoline for trampolineThrow
|
|
Exception: boo
|
|
Error: Object of class stdClass could not be converted to string
|
|
TypeError: preg_replace_callback(): Argument #3 ($subject) must be of type array|string, stdClass given
|
|
|
|
Warning: Array to string conversion in %s on line %d
|
|
Error: Object of class stdClass could not be converted to string
|
|
Error: Object of class stdClass could not be converted to string
|
|
Error: Object of class stdClass could not be converted to string
|
|
TypeError: preg_replace_callback(): Argument #3 ($subject) must be of type array|string, stdClass given
|