php.net |  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
Votes:3
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
 [2004-08-16 20:57 UTC] liit at geeksbynature dot dk
Description:
------------
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:
----------------
boolean
boolean

Actual result:
--------------
integer
boolean

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-17 00:12 UTC] iliaa@php.net
ereg() returns the length of the matched string on success, 
the documentation is wrong. 
 [2004-08-17 00:40 UTC] tomsommer@php.net
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:

<?php
$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";
?>

Result:
1:integer
1:integer
:boolean

According to the docs, it should be:
2:integer
3:integer
:boolean
 [2004-09-06 21:27 UTC] nlopess@php.net
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
?>

Nuno
 [2004-09-10 16:37 UTC] vrana@php.net
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
http://snaps.php.net/.
 
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] phpdocbot@php.net
Automatic comment on behalf of tomsommer
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=ea9a85ca4ad086874dc3f2e4e922b8059e75847e
Log: Fix bug #29712 - ereg() does not return TRUE
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC