PHP 4.0 Bug #7850 Updated: settype() function

From: Date: Sun, 19 Nov 2000 14:23:30 +0000
Subject: PHP 4.0 Bug #7850 Updated: settype() function
Groups: php.dev 
Request: Send a blank email to php-dev+get-38499@lists.php.net to get a copy of this message
ID: 7850 Updated by: stas Reported By: carlos@vlcnet.com.br Status: Closed Bug Type: Unknown/Other Function Assigned To: Comments: First, settype returns boolean, see: http://www.php.net/manual/function.settype.php Second, if you want to convert something to integer, use (int)$var, not settype. Third, maximal available integer number in PHP is 2147483647. This is what gets returned. Use $var+0 if you want to get numeric value form string, no matter what large. Previous Comments: --------------------------------------------------------------------------- [2000-11-16 13:08:03] carlos@vlcnet.com.br Please, verify the script below, this error occurred with others values in this variable too. ------------------------------------------------------------<?php function retorna_cnpj($cnpj) { $new_var = ereg_replace("[/.-]","",$cnpj); echo $new_var . "<br>"; $nada = settype($new_var,"integer"); echo $new_var . "<br>"; return $new_var; } $w_cnpj = "12.345.678/0002-12"; echo $w_cnpj . "<br>"; echo retorna_cnpj($w_cnpj) . "<br>"; ?> ------------------------------------------------------------ It must return 12345678000212 as integer, but php return for me the number: 2147483647 Thanks Carlos Portella --------------------------------------------------------------------------- [2000-11-16 12:55:03] carlos@vlcnet.com.br Please, verify the script below, this error occurred with others values in this variable too. ------------------------------------------------------------ <?php function retorna_cnpj($cnpj) $new_var = ereg_replace("[/.-",$cnpj); $new_var = settype($new_var,"integer"); return $new_var; } $w_cnpj = "12.345.678/0002-12" echo retorna_cnpj($w_cnpj); ?> ------------------------------------------------------------ It must return 12345678000212 as integer, but php return for me the number: 2147483647 Thanks Carlos Portella --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=7850

« previous php.dev (#38499) next »