# 'false' - boolean interpratation

- Thread: https://externals.io/message/10326
- Original archive: https://news-web.php.net/php.internals/10326
- Started by Robert Janeczek on 2004-06-08T18:07:22+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #10327 — Hans Lellelid — 2004-06-08T18:06:58+00:00

URL: https://externals.io/message/10326#10327 · In reply to: #10326

Robert Janeczek wrote:
> is there any way that string 'false' (and its variations with capital
> letters) could be interpeted as boolean of value false? i have xml
> configuration file that has some switches (true/false) in it. when i use
> this values in functions that require booleans i get true every time (as
> string isn`t empty) :/ i hoped that at least with explicit type cast i could
> go around this problem, but i didn`t help.
> how about adding this special case to conversion rules? creating if`s around
> such code doesn`t make me happy at all :]

IMO better as userland function/method (this is extract from a Phing class):

     ...
     private static $TRUE_VALUES = array("on", "true", "t", "yes");
     ...

     public function booleanValue($s) {
         if (is_bool($s)) {
             return $s; // it's already boolean (not a string)
         }
         // otherwise assume it's something like "true" or "t"
         $trimmed = strtolower(trim($s));
         return in_array($trimmed, self::$TRUE_VALUES);
     }


Hans

---

## #10326 — Robert Janeczek — 2004-06-08T18:07:22+00:00

URL: https://externals.io/message/10326#10326

is there any way that string 'false' (and its variations with capital
letters) could be interpeted as boolean of value false? i have xml
configuration file that has some switches (true/false) in it. when i use
this values in functions that require booleans i get true every time (as
string isn`t empty) :/ i hoped that at least with explicit type cast i could
go around this problem, but i didn`t help.
how about adding this special case to conversion rules? creating if`s around
such code doesn`t make me happy at all :]

rash

---

## #10329 — Derrell.Lipman@UnwiredUniverse.com — 2004-06-08T18:31:19+00:00

URL: https://externals.io/message/10326#10329 · In reply to: #10326

"Robert Janeczek" <rashid@ds.pg.gda.pl> writes:

> is there any way that string 'false' (and its variations with capital
> letters) could be interpeted as boolean of value false? i have xml
> configuration file that has some switches (true/false) in it. when i use
> this values in functions that require booleans i get true every time (as
> string isn`t empty) :/ i hoped that at least with explicit type cast i could
> go around this problem, but i didn`t help.
> how about adding this special case to conversion rules? creating if`s around
> such code doesn`t make me happy at all :]

What do eval('false') and eval('true') return?  You can probably just do
eval(xmlText) to get the results you're looking for.  (Just beware that the
xmlText actually contains one of the values "true" or "false", and not some
malicious php code.)

Derrell

---

## #10331 — Nick Loeve — 2004-06-09T00:23:40+00:00

URL: https://externals.io/message/10326#10331 · In reply to: #10329

Derrell Lipman wrote:
> "Robert Janeczek" <rashid@ds.pg.gda.pl> writes:
> 
> 
> > […]
> 
> 
> What do eval('false') and eval('true') return?  You can probably just do
> eval(xmlText) to get the results you're looking for.  (Just beware that the
> xmlText actually contains one of the values "true" or "false", and not some
> malicious php code.)
> 
> Derrell

or use integers in the xml file and force type casting (integer)$xmlText
