Phalanger
Phalanger copied to clipboard
preg_match_all() with PREG_OFFSET_CAPTURE returns differently than PHP
This might actually be a bug with PHP, but Phalanger acts differently from PHP that can cause problems.
When an optional matching group doesn't match in a preg_match_all() call with PREG_OFFSET_CAPTURE, PHP returns "" (an empty string) for that group, whereas Phalanger returns array("",0).
Reproduction code:
preg_match_all('/(x)?/', '', $m, PREG_OFFSET_CAPTURE);
print '<pre>'; var_dump($m); print '</pre>';
PHP returns:
<pre>array(2) {
[0]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(0) ""
[1]=>
int(0)
}
}
[1]=>
array(1) {
[0]=>
string(0) ""
}
}
</pre>
Phalanger:
<pre>array(2) {
[0]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(0) ""
[1]=>
int(0)
}
}
[1]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(0) ""
[1]=>
int(0)
}
}
}
</pre>
Phalanger 3.0 PHP 5.0.4 – 5.5.18.
@mgduk Phalanger's development is mostly discontinued in favor of PeachPie, the more modern compiler and runtime that also targets .NET Core. Please feel free to give that a try.