Robbo
Well-known member
Currently namespaces can't be used for extending a class, as in the following...
Because when you extend in the listener with...
It is trying to eval
which obviously won't work.
So if you make the following changes to XenForo_Application, line 416...
Tested with a couple classes and they all seem to inherit fine, full namespace is just used on the extend and if a namespace exists the eval just starts with that. I haven't however tested the fake base stuff above these lines because I have never needed to use it so not sure how it should be modified.
Just need to know if this can be in 1.2 so I can start coding my listeners like this or make a workaround.
PHP:
<?php namespace Robbo\DataWriter;
class User extends XFCP_User {
// stuff
}
Because when you extend in the listener with...
PHP:
$extend[] = 'Robbo\DataWriter\User';
It is trying to eval
PHP:
class Robbo\DataWriter\User extends XFCP_Robbo\DataWriter\User {}
So if you make the following changes to XenForo_Application, line 416...
PHP:
foreach ($extend AS $dynamicClass)
{
if (strpos($dynamicClass, '\\') !== false)
{
$namespace = substr($dynamicClass, 0, strrpos($dynamicClass, '\\'));
$proxyClass = 'XFCP_' . substr(strrchr($dynamicClass, '\\'), 1);
}
else
{
$namespace = false;
$proxyClass = 'XFCP_' . $dynamicClass;
}
eval(($namespace ? 'namespace ' . $namespace . '; ' : '') . 'class ' . $proxyClass . ' extends \\' . $createClass . ' {}');
XenForo_Application::autoload($dynamicClass);
$createClass = $dynamicClass;
}
Tested with a couple classes and they all seem to inherit fine, full namespace is just used on the extend and if a namespace exists the eval just starts with that. I haven't however tested the fake base stuff above these lines because I have never needed to use it so not sure how it should be modified.
Just need to know if this can be in 1.2 so I can start coding my listeners like this or make a workaround.
Upvote
0