note 50965 added to function.eval

From: Date: Tue, 15 Mar 2005 09:20:00 +0000
Subject: note 50965 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-86450@lists.php.net to get a copy of this message
A small heads up regarding numbers and forms: If you do <?php eval('\$foo = 023;'); ?> The value of $foo will be 19, because 023 is evaluated as an octal number. Why is this interesting? It created an odd problem for me because I had a form field taking a number from the user. This number was part of an eval. The field had a default 0 in it and the user would just put 23 behind that without deleting the 0 first, expecting it (understandably) to have the value 23. Note also that if you do <?php $bar = (integer) "023"; $foobar = (integer) 023; ?> The value of $bar will be 23, as expected, while the value of $foobar will be 19. It is quite consistent but imagine my confusion... In light of this the solution in my case was to do <?php eval('\$foo = (integer) "023";'); ?> ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50965 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50965&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50965&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50965&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50965&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50965&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50965&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86450) next »