|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-10-14 00:05 UTC] daniel at parthenonsoftware dot com
Description:
------------
While the documentation accurately tells the programmer that preg_match returns an int, the documentation does not reflect the meaning of the return value.
As an example, in shell scripting, 0 represents true, where another number typically represents an error code. Returning 0 from a main application means everything went successfully.
Further, in some languages like C/C++, 0 is the default return value, basically meaning "Everything fine nothing to see here move along please". ;-)
The confusion comes from the fact that the preg_match() function returns 1 if a match is found and 0 otherwise.
By adding this sentence to the documentation for preg_match:
The preg_match() function returns 1 if a match is found and 0 otherwise.
A fair bit of confusion would be cleared up by defining the non-standard meaning up front.
Actual result:
--------------
tt
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 21 06:00:02 2025 UTC |
The documentation already clearly states (under the heading "Return Values"): preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. The above essentially paraphrases your own suggested addition.