php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #684 Addition unreliable when adding an integer to a string number from ereg()
Submitted: 1998-08-22 19:34 UTC Modified: 1998-08-23 15:11 UTC
From: ben at isa dot net dot au Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.3 OS: Solaris x86 2.5
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: ben at isa dot net dot au
New email:
PHP Version: OS:

 

 [1998-08-22 19:34 UTC] ben at isa dot net dot au
<?php
  ereg( "([0-9]{1,2})[^0-9]([0-9]{2,4})", "1/05", $regs );
  if ( ($regs[2] <= 50) && ($regs[2] >= 0) )
    $regs[2] += 2000;
  echo "Year: $regs[2]<br>";
?>

The script is meant to return:
Year: 2005<br>

However, it returns:
Year: 2505<br>

Bizzaaaarrrrrreeee! :)

It only seems to happen if the array is assigned with ereg.  A way to get around it is:
$regs[2] = (int)$regs[2] + 2000;
this then returns the correct result.

This error occured on a just-compiled php from the command line with the following configure options:
./configure --with-mod_charset=no --with-gd=no --with-mysql --enable-magic-quotes=yes --disable-debug

Finis!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-08-23 15:11 UTC] zeev
Fixed, thanks for the detailed report!
(the bug was in ereg(), not in the addition code)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 16:01:29 2024 UTC