|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29712 ereg() does not return TRUE
Submitted: 2004-08-16 20:57 UTC Modified: 2004-09-10 16:37 UTC
Avg. Score:2.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: liit at geeksbynature dot dk Assigned:
Status: Closed Package: Regexps related
PHP Version: 4.3.8 OS: Gentoo Linux
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.
Block user comment
Status: Assign to:
Bug Type:
From: liit at geeksbynature dot dk
New email:
PHP Version: OS:


 [2004-08-16 20:57 UTC] liit at geeksbynature dot dk
The function ereg() either returns (boolean)FALSE or (int)1, and not (boolean)FALSE or (boolean)TRUE

Reproduce code:
echo gettype(ereg("foo","foo"));
echo gettype(ereg("foo","bar"));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-17 00:12 UTC]
ereg() returns the length of the matched string on success, 
the documentation is wrong. 
 [2004-08-17 00:40 UTC]
This bug has been fixed in the documentation's XML sources. 
The changes may not appear immediately, since the online and downloadable versions of the documentation need some time to get updated. We would therefore like to ask for your patience in this matter.

Thank you for the report, and for helping us make our documentation better.
 [2004-08-29 18:10 UTC] liit at geeksbynature dot dk
ereg() still only returns int(1) or (boolean)FALSE. I've expanded my test-script a bit:

$a = ereg("fo","fo"); // Simple test to see if documentation is right (it's not)
$b = ereg("bar","foobarbar"); // Is it the position of the first result, that is returned ? (no)
$c = ereg("foo","bar"); // A negative test (works)

echo $a . ":" . gettype($a). "\n";
echo $b . ":" . gettype($b). "\n";
echo $c . ":" . gettype($c). "\n";


According to the docs, it should be:
 [2004-09-06 21:27 UTC]
If I understand, this function should return the legth of the match.
But it seems it has a bug, because it always return 1 if you don't pass the 3rd parameter. Or is it a feature that should be documented?

echo ereg('foo', 'foo foo foo'); //1
echo ereg('foo', 'foo foo foo', $var); //3

echo ereg('foobar', 'foobar foo foo', $var2); //6

 [2004-09-10 16:37 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

"If the optional parameter regs was not passed or the length of the matched string is 0, this functions returns 1."
 [2020-02-07 06:11 UTC]
Automatic comment on behalf of tomsommer
Log: Fix bug #29712 - ereg() does not return TRUE
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 06:01:30 2024 UTC