[php-src] Issue #7917: preg_match and preg_match_all both do not set $matches on regex fail, leaving as it was set prior to call
| From: | cmb69 | Date: | Sun, 09 Jan 2022 23:34:48 +0000 |
| Subject: | [php-src] Issue #7917: preg_match and preg_match_all both do not set $matches on regex fail, leaving as it was set prior to call | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238923@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7917
Comment Author: cmb69
Well, the basic logic is:
````php
function preg_match($pattern, $subject, &$matches) {
switch (match($pattern, $subject)):
case MATCHED:
$matches = whatever_matched();
return 1;
case DID_NOT_MATCH:
$matches = [];
return 0;
case FAILURE:
return false;
}
}
````
If
$matches was an out parameter, I would expect it to be undefined, if
preg_match() failed. Since it is a by-ref parameter, I would expect it to be unmodified
in this case. Maybe "expect" is a bit of an overstatement here; I'd just not rely on
any particular value.
Perhaps this is just something we should document?