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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 18:01:35 2024 UTC