|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-03-21 16:30 UTC] cmb@php.net
[2018-03-21 17:28 UTC] graefrath at femu dot rwth-aachen dot de
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
Description: ------------ preg_match returns false in case of an error. However, not all errors that can occur have corresponding error codes returned by preg_last_error. Additionally, the last error is not cleared when a PCRE function is called and there is no function to manually clear it. This makes it very hard to reliably detect errors such as invalid patterns. Consider the following example: @preg_match("/./u", "\xff"); // returns false and sets preg_last_error to PREG_BAD_UTF8_ERROR @preg_match("invalidpattern", ""); // returns false, but preg_last_error is still PREG_BAD_UTF8_ERROR The only way to detect the invalid pattern error is to catch the PHP warning that is being raised. This seems really inconsistent to me. Since PHP < 7 does not have error_clear_last yet, it is also not trivial to figure out whether you have to look at the last PHP error or the last PCRE error, since a PHP error message starting with preg_ could also be from a previous call. Expected result: ---------------- I expect the return value of preg_last_error to reflect all kinds of errors correctly, not just some of them. Actual result: -------------- preg_last_error returns a valid error code only for some errors, while other are indicated by PHP warnings.