isBool() public static method

This actually check only for TRUE and FALSE because 1 or 0 are actually numbers and are parsed by specific methods.
public static isBool ( string $str ) : boolean
$str string String to be checked.
return boolean
示例#1
0
 public function testIsBool()
 {
     $this->assertTrue(Context::isBool('true'));
     $this->assertTrue(Context::isBool('false'));
     $this->assertFalse(Context::isBool('tru'));
     $this->assertFalse(Context::isBool('falsee'));
 }
示例#2
0
 /**
  * Parses a boolean.
  *
  * @return Token
  */
 public function parseBool()
 {
     if ($this->last + 3 >= $this->len) {
         // At least `min(strlen('TRUE'), strlen('FALSE'))` characters are
         // required.
         return null;
     }
     $iBak = $this->last;
     $token = $this->str[$this->last] . $this->str[++$this->last] . $this->str[++$this->last] . $this->str[++$this->last];
     // _TRUE_ or _FALS_e
     if (Context::isBool($token)) {
         return new Token($token, Token::TYPE_BOOL);
     } elseif (++$this->last < $this->len) {
         $token .= $this->str[$this->last];
         // fals_E_
         if (Context::isBool($token)) {
             return new Token($token, Token::TYPE_BOOL, 1);
         }
     }
     $this->last = $iBak;
     return null;
 }