note 113693 added to function.is-bool
| From: | MichaelSmith | Date: | Sun, 17 Nov 2013 01:17:33 +0000 |
| Subject: | note 113693 added to function.is-bool | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197543@lists.php.net to get a copy of this message | ||
The function in the last comment also converts the string 'false' to a true boolean.
Here's a function that does what I think was intended:
<?php
function toBool($var) {
if (!is_string($var)) return (bool) $var;
switch (strtolower($var)) {
case '1':
case 'true':
case 'on':
case 'yes':
case 'y':
return true;
default:
return false;
}
}
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.is-bool.php
Edit -- https://master.php.net/note/edit/113693
Del: integrated -- https://master.php.net/note/delete/113693/integrated
Del: useless -- https://master.php.net/note/delete/113693/useless
Del: bad code -- https://master.php.net/note/delete/113693/bad+code
Del: spam -- https://master.php.net/note/delete/113693/spam
Del: non-english -- https://master.php.net/note/delete/113693/non-english
Del: in docs -- https://master.php.net/note/delete/113693/in+docs
Del: other reasons-- https://master.php.net/note/delete/113693
Reject -- https://master.php.net/note/reject/113693
Search -- https://master.php.net/manage/user-notes.php