php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7850 settype() function
Submitted: 2000-11-16 12:55 UTC Modified: 2000-11-19 09:23 UTC
From: carlos at vlcnet dot com dot br Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.0 OS: Red Hat Linux 6.2
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: carlos at vlcnet dot com dot br
New email:
PHP Version: OS:

 

 [2000-11-16 12:55 UTC] carlos at vlcnet dot com dot 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-16 13:08 UTC] carlos at vlcnet dot com dot 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-19 09:23 UTC] stas@php.net
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.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 19:01:28 2024 UTC