php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53056 Incomplete information for return value of preg_match
Submitted: 2010-10-14 00:05 UTC Modified: 2010-10-14 11:18 UTC
From: daniel at parthenonsoftware dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.3.3 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daniel at parthenonsoftware dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-14 04:49 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2010-10-14 04:49 UTC] aharvey@php.net
The preg_match() return values section already seems completely clear to me.
 [2010-10-14 10:55 UTC] daniel at parthenonsoftware dot com
Then I would like to invite you to speak english
 [2010-10-14 11:18 UTC] salathe@php.net
-Status: Wont fix +Status: Bogus
 [2010-10-14 11:18 UTC] salathe@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 15:01:33 2025 UTC