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

Announcement PHP typehinting changes phase 2

Discussion in 'News' started by dktapps, May 18, 2018.

  1. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    Work is underway once again to modernize and strict up the API, this time to PHP 7.2 standards.

    You'll probably remember the last time a strict craze happened (API 3.0.0-ALPHA7), which was very messy. This is here to give some advance warning to developers on the change set to expect, and how to prepare, to hopefully minimize the impact.

    What exactly is going to change?
    - void and ?nullable typehints will be applied everywhere it is reasonable to do so. You can guard against this in advance by adding return typehints to your code that extends or implements PM interfaces (return typehints may be made more strict by child classes).
    - ?nullable typehints will be applied to parameters where needed.

    Mostly these changes shouldn't be quite as turbulent as ALPHA7 was because this is a smaller changeset.

    Why typehints?
    Type declarations (in combination with strict types) do a range of things, including making code easier to read, exposing bugs in code more quickly (which improves maintainability) and improving safety of the API.

    The goal since ALPHA7 has been to expose a typed API to plugins, such that (since most plugins don't use strict types) variables will get automatically converted at the API layer to ensure sane functionality in the core while also allowing plugin devs to do whatever crazy PHP weak-type things they like.

    However, having said that, weak types are very scary, and I strongly recommend you try strict types for serious code.

    Read more about strict types and type declarations in PHP 7.x here.
     
  2. Flavius12

    Flavius12 Spider Jockey

    Messages:
    32
    GitHub:
    flavius12
    It's very difficult for a C/C++ programmer to work without datatypes. This is one of the reasons which let me hate PHP.
     
    HimbeersaftLP and dktapps like this.
  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.