note 94561 added to function.settype
| From: | Anonymous at osu1 dot php dot net | Date: | Thu, 12 Nov 2009 01:45:26 +0000 |
| Subject: | note 94561 added to function.settype | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162790@lists.php.net to get a copy of this message | ||
What michaltrutman is referring to is setting a variable's type implicitly instead of
explicitly.
Two common one's that were missed on his/her post are:
Changing a variable or expression to boolean using a double-not:
<?php
$a = !!$a; // $a is now boolean.
?>
And you can change a float to an integer using shift operators if the fraction does not matter. This
is the same as the floor function:
<?php
$a <<<= 0; // $a is now an integer.
// or..
$a >>>= 0; // $a is now an integer.
?>
----
Server IP: 69.147.83.197
Probable Submitter: 76.25.107.41
----
Manual Page -- http://www.php.net/manual/en/function.settype.php
Edit -- https://master.php.net/note/edit/94561
Del: integrated -- https://master.php.net/note/delete/94561/integrated
Del: useless -- https://master.php.net/note/delete/94561/useless
Del: bad code -- https://master.php.net/note/delete/94561/bad+code
Del: spam -- https://master.php.net/note/delete/94561/spam
Del: non-english -- https://master.php.net/note/delete/94561/non-english
Del: in docs -- https://master.php.net/note/delete/94561/in+docs
Del: other reasons-- https://master.php.net/note/delete/94561
Reject -- https://master.php.net/note/reject/94561
Search -- https://master.php.net/manage/user-notes.php