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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 + 16 = ?
Subscribe to this entry?

 
 [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: Sun May 19 12:01:30 2024 UTC