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

About namespaces in Alpha 1.4

Comments in 'Plugin Development' started by Dinokiller, May 10, 2014.

  1. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Now a few plugin developers will know that "namespaces" are being added into Alpha 1.4 (not sure if they were there already). Now this is quite easy for me to understand as namespaces are basically like packages in Java. However I can't convince myself that you're allowed to do these:

    PHP:
    $test = new test\example\plugin\Thing();
    and I'm really confused with this:
    PHP:
    if(class_exists("Hello")) {
        
    // Do stuff
    }
    /*
    Would this count "test\plugin\Hello" or just classes with no namespace defined?
    */
    }
    Thanks for the help.
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
  3. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I am not sure about the first one but I don't know why you would need it.
  5. InusualZ
    Offline

    InusualZ Active Member Plugin Developer

    Joined:
    Aug 23, 2013
    Posts:
    220
    Plugins:
    1
    Minecraft User:
    Inusu4lZ
    If you are not using the namespace of the function you can't acces to the function directly.
    PHP:
    <?php
    //Example
    //Wrong
    if(class_exist("Hello"))
    {
        
    // Do Stuff
    }

    //Good
    if(class_exist("\\test\\plugin\\namespace\\Hello"))
    {
        
    // Do Stuff
    }

    class_exist()
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Add: It is a bad practice to use full namespaces inside the main code (without `use`). It is easier to fix typos with that.
    Falk likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What about no \\ at beginning of string literal?

Share This Page

Advertisement