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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 19:01:36 2025 UTC