Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

preg_match_all() with PREG_OFFSET_CAPTURE returns differently than PHP #41

Open
mgduk opened this issue Dec 3, 2014 · 1 comment
Open

Comments

@mgduk
Copy link

mgduk commented Dec 3, 2014

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
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants