Bug #684: Addition unreliable when adding an integer to a string number from ereg()

From: Date: Sat, 22 Aug 1998 23:34:07 +0000
Subject: Bug #684: Addition unreliable when adding an integer to a string number from ereg()
Groups: php.dev 
Request: Send a blank email to php-dev+get-498@lists.php.net to get a copy of this message
From: ben@isa.net.au Operating system: Solaris x86 2.5 PHP version: 3.0.3 PHP Bug Type: Misbehaving function Bug description: <?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! -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#498) next »