예제 #1
0
 /**
  * Process a scalar value.
  * Handles string literals including defined constants
  * @return mixed
  * @throws Exception when there's an unexpected value
  */
 protected function process_value()
 {
     # String literals
     if ($this->tokens->matches(T_STRING)) {
         $t_token = $this->tokens->pop();
         $t_value = $t_token[1];
         # PHP Standard string literals
         switch (strtolower($t_value)) {
             case 'null':
                 return null;
             case 'true':
                 return true;
             case 'false':
                 return false;
         }
         # Defined constants
         $t_value = $this->constant_replace($t_value);
         if ($t_value !== $t_token[1]) {
             return $t_value;
         }
         throw new Exception("Unknown string literal '{$t_value}'");
     }
     # Strings
     if ($this->tokens->matches(T_CONSTANT_ENCAPSED_STRING)) {
         $t_value = $this->tokens->pop();
         return (string) stripslashes(substr($t_value[1], 1, -1));
     }
     # Numbers
     $t_negate = 1;
     if ($this->tokens->matches('-')) {
         $this->tokens->pop();
         $t_negate = -1;
     }
     if ($this->tokens->matches('+')) {
         $this->tokens->pop();
     }
     # Integers
     if ($this->tokens->matches(T_LNUMBER)) {
         $t_value = $this->tokens->pop();
         return $t_negate * (int) $t_value[1];
     }
     # Floating point
     if ($this->tokens->matches(T_DNUMBER)) {
         $t_value = $this->tokens->pop();
         return $t_negate * (double) $t_value[1];
     }
     # Anything else
     throw new Exception("Unexpected value" . $this->tokens->value());
 }