note 50255 added to function.settype

From: Date: Wed, 23 Feb 2005 05:50:25 +0000
Subject: note 50255 added to function.settype
Groups: php.notes 
Request: Send a blank email to php-notes+get-85401@lists.php.net to get a copy of this message
I had a problem with PHP destroying the value of my integer with leading zeros as follows: $agentnum = "007"; $agentnum = settype($agentnum, "int"); echo $agentnum; // will show up as 1 instead of 7! Oddly enough, this works fine, (at least for PHP 4.3): $agentnumber = "007"; $agentnumber += 0; // convert $number to numeric type echo $agentnumber; // will now show up as 7! If you do this for gods sake leave a comment on the line because its definitely not by-the-book coding. Another commentor here has used regular expressions to weed out the leading zeros, so I know its not the only solution. I also tried the equivelant of: $agentnum = "007"; $agentnum = (int)$agentnumber; echo $agentnum; But the result is a nonsense number, probably by using the concatenation of the ASCII codes as the integer. ---- Manual Page -- http://www.php.net/manual/en/function.settype.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50255 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50255&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50255&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50255&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50255&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50255&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50255&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85401) next »