note 99654 added to function.settype

From: Date: Sat, 28 Aug 2010 21:17:16 +0000
Subject: note 99654 added to function.settype
Groups: php.notes 
Request: Send a blank email to php-notes+get-172142@lists.php.net to get a copy of this message
With reply to Chris Sullins and Michael Benedict, I don't find this behavior strange: <?php echo var_dump( (int)'' ); // int(0) echo var_dump( (float)array('a'=>'b') ); // float(1) ?> This is due to the fact that an uninitialized variable is null, which converts to a 0. As does boolean false or an empty string or array. When a value is not empty, such as my above array, it is converted to a 1 (integer/float) or true (boolean). When changing between arrays and objects, it of course made sense to keep the fields intact (array key/values and object properties/values). Cheers, Chris. ---- Server IP: 69.147.83.197 Probable Submitter: 195.158.87.147 ---- Manual Page -- http://www.php.net/manual/en/function.settype.php Edit -- https://master.php.net/note/edit/99654 Del: integrated -- https://master.php.net/note/delete/99654/integrated Del: useless -- https://master.php.net/note/delete/99654/useless Del: bad code -- https://master.php.net/note/delete/99654/bad+code Del: spam -- https://master.php.net/note/delete/99654/spam Del: non-english -- https://master.php.net/note/delete/99654/non-english Del: in docs -- https://master.php.net/note/delete/99654/in+docs Del: other reasons-- https://master.php.net/note/delete/99654 Reject -- https://master.php.net/note/reject/99654 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172142) next »