Lack of interest Better Exceptionmessage for the handler factories

Dan

Well-known member
This code
PHP:
public static function create($class)
   {
     $class = XenForo_Application::resolveDynamicClass($class);
     if (XenForo_Application::autoload($class))
     {
       $obj = new $class();
       if ($obj instanceof XenForo_AlertHandler_Abstract)
       {
         return $obj;
       }
     }

     throw new XenForo_Exception("Invalid user alert handler '$class' specified");
   }
will throw always

Invalid user alert handler '' specified
if the class doesn't exist, resolveDynamicClass will return false and $class gets overwritten with false and won't contain the classname anymore.


I would suggest to replace it with

PHP:
public static function create($class)
   {
     $classResolved = XenForo_Application::resolveDynamicClass($class);
     if (XenForo_Application::autoload($classResolved ))
     {
       $obj = new $classResolved ();
       if ($obj instanceof XenForo_AlertHandler_Abstract)
       {
         return $obj;
       }
     }

     throw new XenForo_Exception("Invalid user alert handler '$class' specified");
   }
because this way we'll get the classname which caused this problem instead of the empty string '' ;)
 
Last edited by a moderator:
Top