Пример #1
0
 /**
  * Sets the given variable in the current scope to given value
  * 
  * @param PC_Obj_Variable $var the variable to set
  * @param PC_Obj_MultiType $value the value
  * @param bool $isref whether to store a reference (default = false)
  * @return PC_Obj_MultiType the value
  */
 public function set_var($var, $value, $isref = false)
 {
     if (!$var instanceof PC_Obj_Variable) {
         return $this->handle_error('$var is invalid');
     }
     if (!$value instanceof PC_Obj_MultiType) {
         return $this->handle_error('$value is invalid');
     }
     $varname = $var->get_name();
     $scopename = $this->scope->get_name();
     // generate error for assignments of void
     if ($value->contains(new PC_Obj_Type(PC_Obj_Type::VOID))) {
         $this->report_error('Assignment of void to $' . $varname, PC_Obj_Error::E_S_VOID_ASSIGN);
     }
     $this->vars->backup($var, $this->scope);
     // if we are putting the value into an array, tell the var container about that, too
     if ($var->get_array_ref() !== null) {
         $this->vars->backup($var->get_array_ref(), $this->scope);
     }
     if ($isref) {
         $var->set_type($value);
     } else {
         $var->set_type(clone $value);
     }
     if ($varname) {
         $var->set_function($this->scope->get_name_of(T_FUNC_C));
         $var->set_class($this->scope->get_name_of(T_CLASS_C));
         $this->vars->set($scopename, $var);
     }
     return $value;
 }