DEVSENSE / Phalanger

PHP 5.4 compiler for .NET/Mono frameworks. Predecessor to the opensource PeachPie project (www.peachpie.io).
http://v4.php-compiler.net/
Apache License 2.0
381 stars 92 forks source link

preg_match_all() with PREG_OFFSET_CAPTURE returns differently than PHP #41

Open mgduk opened 10 years ago

mgduk commented 10 years ago

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.

bfistein commented 6 years ago

@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.