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

Announcement Upcoming changes in API and PHP7

Comments in 'PocketMine News' started by shoghicp, Jul 22, 2015.

Thread Status:
Not open for further replies.
  1. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    438
    Plugins:
    14
    Minecraft User:
    shoghicp
    Hello!

    As you may or may not know, PHP7 (the next version of the language version PocketMine uses) is going to be released soon. This has been highly anticipated, as this update will bring huge performance improvements, and PocketMine will benefit of this greatly (expect at least two times as fast in the worst case!). It also adds new language features, which we will be using.

    However, to fully use all the new features, we need to do partial backwards-incompatible changes to the plugin API, so the version will be bumped to 2.0.0. But wait! Don't start strong arguments yet. Why are we doing this? What is going to happen to existing plugins? Will I have to do something? Should I hate @shoghicp? Just read this big text so we can clarify all of that.

    Why are we doing this?
    PHP7 comes with a lot of new features and performance improvements. We would like to use all of the new features so the development process can be faster, have better code, and improve the overall performance besides the base enhancements.
    We had two options, just update to PHP7 with the current code (which should work OOB) without using the new features, or use the new features. Unfortunately, using the new features means modifying the method signatures, so extending those classes with old code will break. The fix is simple and fast, nevertheless, it breaks plugins, so it requires bumping the major version to 2.
    This is no big change as it was from the infamous "Old API" to the "New API" (current API, since 1.4), so you don't have to learn everything again.

    Short version: PHP7 has new awesome stuff that requires modifying method signatures. This breaks backwards-compatibility for some plugins (with a simple and fast fix), so we are bumping the major version.


    What is going to happen to existing plugins?
    First, you should contact the developers of your plugins about this and link them here (or future information). I recommend the developers itself to inform their users of this change.
    Second, and this will be mostly for developers, you will have to upgrade and change the target version.
    If your plugin only calls methods and does basic stuff, you should be almost done after bumping the version. If you extend some class or implement an interface, it will be different. Starting on PHP7, scalar type hints can be added to your methods (not only class hints anymore!). On the PocketMine core, this was done before using Doc comments, but now we will do something like this:

    Before
    PHP:
    public function grow($x$y$z){
            return new 
    AxisAlignedBB($this->minX $x$this->minY $y$this->minZ $z$this->maxX $x$this->maxY $y$this->maxZ $z);
        }
    After
    PHP:
    public function grow(float $xfloat $yfloat $z) : AxisAlignedBB{
            return new 
    AxisAlignedBB($this->minX $x$this->minY $y$this->minZ $z$this->maxX $x$this->maxY $y$this->maxZ $z);
        }
    As you can see, the changes will be minimal and you should just update your method signatures. We are also going to remove all the deprecated methods, classes, properties and other stuff. You can see them as they are marked with @deprecated. You don't have to learn everything from scratch, in fact, everything will be the same (but easier, as you can know what that argument is now!). More information will be available as we update the core to support everything.

    Short version: Most of them will work without problems, others will have to do minor changes.


    Will I have to do something?
    If you use plugins: inform your plugin developers about this. Besides that, you will have to update to a new version of plugins as they are available.
    If you develop plugins: see text above.


    Should I hate @shoghicp?
    Hmm, that's your decision. But you can blame me!


    WHAT DO I NEED TO DO NOW?!?!
    Nothing. For now, wait, more information will be available later (after we update the core), and this will start happening next month. Just wait patiently, and try to tell developers you know about this so they prepare for it (and learn the new awesome way to do it!)
    Last edited: Jul 22, 2015
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,444
    Plugins:
    14
    I have a question. Why will we have to update our plugins? I realize that we need PHP7 to use scalar type hinting, but we can still do it the old way (without type hinting), and it would still be valid.
  3. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    438
    Plugins:
    14
    Minecraft User:
    shoghicp
    READ!

    You don't need to add type-hints everywhere, just on the classes that extend from PocketMine. It is recommended, though, as you will get less undefined behavior and more performance.
  4. TruDan
    Offline

    TruDan New Member

    Joined:
    Oct 24, 2014
    Posts:
    8
    Minecraft User:
    TruDan
    #BlameShoghi!!!!!!!!!
    AndrewBit, remote_vase, Ishan and 7 others like this.
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    822
    Plugins:
    15
    Minecraft User:
    Flavius12
    Yay like all other programming languages! :D
    @shoghicp, will we be able to try PocketMine with PHP 7 before October?
    Then why shouldn't we blame you? :p
    You are working very hard. Lol I'm writing a server software for my game ( and obviously also the game) and I'm losing lot of time on finding bugs, adding new features...
    You are working very hard on MCPE and PocketMine!!! Blame you :)
    Last edited: Jul 22, 2015
  6. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    Finally :D
  7. KnownUnown
    Offline

    KnownUnown Active Member Plugin Developer

    Joined:
    Aug 22, 2013
    Posts:
    65
    Plugins:
    1
    Minecraft User:
    KnownUnown
    I still blame Shoghi. Is anything new coming along the lines of pthreads?
  8. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    446
    Minecraft User:
    wiez
    Will you also add type hinting for the return types, because you didn't use it in the example?
    Falk, hoyinm14mc, PEMapModder and 2 others like this.
  9. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    438
    Plugins:
    14
    Minecraft User:
    shoghicp
    It's open source :)

    That's what triggered this post. Look at this. I'll try to set up the binaries next week.

    I forgot about them! I updated the post now
  10. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
  11. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,444
    Plugins:
    14
    ~ A wild Unown steps out of the woods.
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    lol... I assume this will make the code much more readable?
  13. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Aw , I can't wait!
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,342
    Plugins:
    11
    Minecraft User:
    PEMapModder
    @shoghicp since you're so worried that instanceof calls lag the server, remove all type hints! :p
  15. sekjun9878
    Offline

    sekjun9878 Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    108
    Plugins:
    1
    Minecraft User:
    sekjun9878
    Personally I feel like this decision has been made by @shoghicp personally, without proper discussion with any members of The PocketMine Team nor any proper discussion with any of the developers. A backwards incompatible change without an RFC? I don't see how strict types will be beneficial, maybe apart from the levels module. If anything, it will just add boilerplate casts everywhere - strict types are meant to be used sparingly, and at appropriate critical points. It really feels like strict type is being used just for the sake of using the new features in PHP7, but any experienced developers will know why jumping at an untested hype is a bad idea. But hey, convince me otherwise :D
    CrazedMiner, JDTech, Falk and 3 others like this.
  16. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    438
    Plugins:
    14
    Minecraft User:
    shoghicp
    This was discussed on #pocketmine and #pocketmine-team before. Please check the logs before commenting :)
    madhon, 64FF00 and jojoe77777 like this.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,342
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So your discussion conclusion is that more instance checks is beneficial :)
    JDTech, 64FF00 and LDX like this.
  18. DvD
    Offline

    DvD New Member

    Joined:
    Jul 22, 2015
    Posts:
    1
    Minecraft User:
    MHDa
    Genial shoghicp...!!! Esto va a dar mucha vida a las futuras PE. Para cuando un soporte/comunidad de Mojang espaƱol??

    Gracias
    Last edited: Jul 23, 2015
  19. ProjectInfinity
    Offline

    ProjectInfinity Active Member Plugin Developer

    Joined:
    Sep 7, 2014
    Posts:
    112
    Plugins:
    3
    Minecraft User:
    ProjectInfinity
    Good stuff.
  20. Rendum
    Offline

    Rendum New Member

    Joined:
    Mar 9, 2015
    Posts:
    3
    Minecraft User:
    Rendum
    good news, I think most glitches I had are fixed, the pushing back bug is rarer, and I think I see biomes? in some servers? or are they player made?
Thread Status:
Not open for further replies.

Share This Page

Advertisement