1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Implemented Allow namespace use in listeners

Discussion in 'Closed Suggestions' started by Robbo, Jun 30, 2013.

  1. Robbo

    Robbo Well-Known Member

    Currently namespaces can't be used for extending a class, as in the following...

    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 {}
    which obviously won't work.

    So if you make the following changes to XenForo_Application, line 416...

    PHP:
                    foreach ($extend AS $dynamicClass)
                    {
                        if (
    strpos($dynamicClass'\\') !== false)
                        {
                            
    $namespace substr($dynamicClass0strrpos($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.
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    Why would you use namespaces when XenForo itself doesn't? Effectively causing your minimum PHP version to be higher than XenForo's.
     
  3. Jeremy P

    Jeremy P Well-Known Member

    Why should you not be able to if you want to?
     
    lol768, JulianD and xf_phantom like this.
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    I don't think XenForo should have extra code to support something they themselves don't utilize. And until XenForo ups its minimum required version, I don't feel its necessary to support name spaced classes.
     
  5. Jeremy P

    Jeremy P Well-Known Member

    So if they don't utilize certain template and code hooks in the ES or Resource Manager they should take those out too right? Just a bunch of extra code to support things they don't use themselves :rolleyes: Oh wait, those are for addons.. which should be able to use them how they want?

    They're on ZF1 so they're not going to up the minimum version anytime soon. PHP 5.3 itself is EOL, you should be able to make full use of namespaces if you want to.
     
    JulianD and xf_phantom like this.
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    You misunderstand my statement. Namespaces are a programming system they don't utilize themselves, however, they do utilize hooks and code event listeners. I don't see a real use in XenForo implementing, testing, and supporting something that they most likely won't utilize until XenForo 2.0 (most likely time to upgrade Zend and/or remove it to not break backwards compatibility).
     
  7. Jeremy P

    Jeremy P Well-Known Member

    My point is this request is for addons to make use of, and addons should be able to make use of any PHP syntax they want, especially now that namespaces exist in all supported versions of PHP. Just because they don't use it themselves doesn't mean it shouldn't be supported.

    I get it would cause incompatibility with users running XF on 5.2, but that's not my problem. I as a developer should be able to choose a greater minimum required version if I want. I personally would like to namespace my addons, the majority of which are private to me anyways so compatibility with other setups isn't my concern.
     
    JulianD and xf_phantom like this.
  8. xf_phantom

    xf_phantom Well-Known Member

    I never used namespaces for proxy classes, because there's IMO no real benefit... You'll never use the classname of the proxy class in other classes, except in the listener declaration (or however this is being called) , but why not?:D

    XenForo shouldn't stop anybody to use 5.3, 5.4 or even 5.5 features, just because xenforo requires 5.2. I don't want to live in the past and stick with 5.2 code (

    Just think of all the new great features in php 5.3 (namespaces, closures) ,5.4 (traits) and now all the great new features in 5.5:love::love: oooooooooooh, how i fall in love with some of them like the usage of list inside foreach

    As long as it's just a minimal change in xf core and doesn't bring new BC problems, why not?(just like the small change in 1.1.4?, to support namespaces in the xf autoloader)
     
    Last edited: Jun 30, 2013
    JulianD and Jeremy P like this.
  9. Robbo

    Robbo Well-Known Member

    I have just read some very silly posts. This isn't 2006. Get with the times.
     
  10. Jeremy

    Jeremy XenForo Moderator Staff Member

    Get with the times? I'm fairly sure that the 'times' still have a majority of users on 5.2. I'm sorry that alienating a majority of users is not in my end goal.
     
  11. Jeremy P

    Jeremy P Well-Known Member

    This functionality doesn't break BC though, I don't see how this is alienating in the slightest. You're still welcome to pretend namespaces don't exist just like you did a week ago, if I want to "alienate"' 5.2 users I should have that choice as an addon developer.
     
    JulianD likes this.
  12. Mike

    Mike XenForo Developer Staff Member

    The suggested code would actually break XF with PHP 5.2 so that would break BC... It's possible to do it with out breaking BC as far as I can tell though, so I've done that for the next beta.
     
    Last edited: Jul 3, 2013
    Sadik B, psTubble27, JulianD and 4 others like this.
  13. Robbo

    Robbo Well-Known Member

    Haha what? I have issues with my add-ons with PHP 5.2. They do not work. The amount of time it took me to try find what stupid **** PHP was doing was more than it took for the customer (a single customer on an OLD version of PHP) to just see about updating his PHP version. It will literally be cheaper and quicker for me to help people upgrade PHP 5.2 or choose a host that isn't crap.

    What in it doesn't work with 5.2? Just curious. And big thanks for adding this.
     
  14. Mike

    Mike XenForo Developer Staff Member

    You were adding the namespace separator to the create class in all cases.
     
    psTubble27 likes this.
  15. psTubble27

    psTubble27 Well-Known Member

    Are you part of the XF developer team?
     
    JulianD likes this.
  16. Jeremy

    Jeremy XenForo Moderator Staff Member

Share This Page