1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Can I use PHP "native" functions in a Plugin?

Discussion in 'Development' started by Minetron26, Mar 25, 2019.

  1. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Well, the title says almost everything, is it possible to use any of the PHP functions and / or declarations with the PocketMine API?, or does not detect them as valid, for example using the declaration:
    PHP:
    require
    in the main class of the plugin.
     
  2. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    yeah man
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Yes, all plugins have permission to go anything PHP allows. However, some functions do not work as expected. For example, sleep() will literally stop the whole server instead of just stopping for one player. As for require, pay attention to the existing class autoloader.
     
    jasonwynn10 and Minetron26 like this.
  4. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Well, thanks for clarifying it, but I respect the declaration require, because I have not been able to use it correctly?
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Why do you need to use `require`? Always place classes in PSR-0 structure and they will be automatically `require`d by the autoloader.
     
    Minetron26 likes this.
  6. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    I am doing a test for use the functions defined in other file, but obtaining that file since a server and not directly since the plugin.
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I don't understand what exactly you mean. Any examples?
     
    Minetron26 likes this.
  8. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    An example, I have a storage server, in which I store a file that uses the PocketMine API to declare functions, for example that the function called: "sayHello()" sends a message saying hello to the player, so my idea is use the "require" statement to obtain that file and use that function.
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Make a class and call static methods on it.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.