/** * Handles the instanceof-operator * * @param PC_Obj_MultiType $e the expression * @param PC_Obj_MultiType $name the name of the class * @return PC_Obj_MultiType the result */ public function handle_instanceof($e, $name) { if (!$e instanceof PC_Obj_MultiType) { return $this->handle_error('$e is invalid'); } $cname = $name->get_string(); // if we're in a loop or the name is not a string, give up if ($this->vars->is_in_loop() || $cname === null) { return PC_Obj_MultiType::create_bool(); } // if we don't know the type or its class we can't say wether its a superclass $classname = $e->get_classname(); if ($classname === null) { return PC_Obj_MultiType::create_bool(); } // class-name equal? if (strcasecmp($classname, $cname) == 0) { return PC_Obj_MultiType::create_bool(true); } // if the class is unknown we can't say more $class = $this->env->get_types()->get_class($classname); if ($class === null) { return PC_Obj_MultiType::create_bool(); } // check super-classes $super = $class->get_super_class(); while ($super != '') { if (strcasecmp($super, $cname) == 0) { return PC_Obj_MultiType::create_bool(true); } $superobj = $this->env->get_types()->get_class($super); if ($superobj === null) { break; } $super = $superobj->get_super_class(); } // check interfaces if ($this->is_instof_interface($class->get_interfaces(), $cname)) { return PC_Obj_MultiType::create_bool(true); } return PC_Obj_MultiType::create_bool(false); }