Not a bug resolveDynamicClass issue with namespace and $fakeNeeded

xfrocks

Well-known member
I have found an issue with the way XenForo_Application::resolveDynamicClass deals with fake class. It will generate invalid code if the $class is in some namespace.

PHP:
        if ($fakeNeeded)
        {
            if (!$extend)
            {
                return false;
            }

            eval('class ' . $class . ' extends ' . $fakeBase . ' {}');
        }

Probably it needs to be process in the same way when creating $proxyClass?

PHP:
                    // XenForo Class Proxy, in case you're wondering
                    $proxyClass = 'XFCP_' . $dynamicClass;
                    $namespaceEval = '';

                    $nsSplit = strrpos($dynamicClass, '\\');
                    if ($nsSplit !== false && $ns = substr($dynamicClass, 0, $nsSplit))
                    {
                        $namespaceEval = "namespace $ns; ";
                        $proxyClass = 'XFCP_' . substr($dynamicClass, $nsSplit + 1);
                        $createClass = '\\' . $createClass;
                    }

                    eval($namespaceEval . 'class ' . $proxyClass . ' extends ' . $createClass . ' {}');
 
I know I made some changes before, but I don't think I'm going to change this. I have rejected other namespace related changes given that XF is still fundamentally not built with namespaces so becoming namespace-aware is generally out of the current scope. Additionally, the class passed in is usually considered to be an XF class (or at least XF-like) and thus wouldn't be using namespaces. By default, the only place where this path is triggered is view classes (I believe).
 
I see your point. And yes, I encountered this issue with a view class from another add-on. Probably keep it in mind when you finally support namespace in XenForo 2.0 then?

@Nobita.Kun: probably you need to stop using namespaces until the core software supports it ;)
 
I see your point. And yes, I encountered this issue with a view class from another add-on. Probably keep it in mind when you finally support namespace in XenForo 2.0 then?

@Nobita.Kun: probably you need to stop using namespaces until the core software supports it ;)
Yep! I've try another way for that :oops:
Hope that 2.0 support full namespaces :)
 
Back
Top Bottom