Description
When using preg_replace_callback, the callback receives a parameter that the type checker does not recognize as an array. This causes errors such as "Cannot index non-array" inside the callback body.
Reproduction
$result = preg_replace_callback(
'/(\d+)/',
function($matches) {
return '[' . $matches[0] . ']'; // Type error on $matches[0]
},
'price: 123 and 456'
);
Expected behavior
The code compiles and runs. $matches is a standard PCRE matches array ($matches[0] = full match, $matches[1] = first capture, etc.).
Actual behavior
Compile error: Cannot index non-array
Environment
elephc 0.21.8
Possible root cause
The builtin signature and/or type inference for preg_replace_callback does not correctly model the type of the array passed to the callback (it should be array<int, string> or array<string> depending on implementation).
See:
src/types/checker/builtins/ (regex / preg category)
src/types/signatures.rs
Additional context
Part of Round 2 preg stress testing.
This makes a very common PHP pattern (preg_replace_callback) unusable without casts or workarounds.
Suggested labels: bug, php-compatibility, type-checker, regex
Description
When using
preg_replace_callback, the callback receives a parameter that the type checker does not recognize as an array. This causes errors such as "Cannot index non-array" inside the callback body.Reproduction
Expected behavior
The code compiles and runs.
$matchesis a standard PCRE matches array ($matches[0]= full match,$matches[1]= first capture, etc.).Actual behavior
Compile error:
Cannot index non-arrayEnvironment
elephc 0.21.8
Possible root cause
The builtin signature and/or type inference for
preg_replace_callbackdoes not correctly model the type of the array passed to the callback (it should bearray<int, string>orarray<string>depending on implementation).See:
src/types/checker/builtins/(regex / preg category)src/types/signatures.rsAdditional context
Part of Round 2 preg stress testing.
This makes a very common PHP pattern (
preg_replace_callback) unusable without casts or workarounds.Suggested labels:
bug,php-compatibility,type-checker,regex