PHP - what is the niche of the language and will PHP8 help solve pressing problems (spoiler: IMHO not)

class Number {
    private int|float $number;

    public function setNumber(int|float $number): void {
        $this->number = $number;
    }

    public function getNumber(): int|float {
        return $this->number;
    }
}

In one of the issues of the Zinc Prod podcast, we briefly discussed what would be new in PHP8. After recording, I decided to write an article to formulate my thoughts on the position of PHP in modern development.

Let's determine in general what niche the language occupied / occupies, and where it moves

Initially, the language was positioned as a simple tool, which out of the box has everything you need for the web .


On the one hand, this is true: without additional libraries, for example, you can extract the POST request parameters from the superglobal variable $ _POST and insert them into mysql using the built-in functions, and this seems to be great.


It is also very important that the β€œborn to die” model (for example, in php-fpm) simplified and simplifies development to madness: you do not need to know what locks, deadlocks, memory leaks, etc. No need to write await before each line of code, etc.


The script started working on an incoming HTTP request, worked in a separate process, without talking to anyone, and died, clearing everything after itself. Very easy to program. The entry threshold is near zero.


, : β€” .


, , . .



: , , SPA- .. php 10000 : php-fpm worker . 10000 .


, , ReactPHP, Swoole, Amphp, , PHP. , . , Swoole 5? ? (Go nodejs) php .


: Go , , . nodejs , async/await Promise. .


PHP- - ReactPHP? !


, , . API . GRPC- php 100500 . .


, PHP .


. , PHP, HTTP- β€” . API, β€” . .. io-bound PHP , nodejs/golang/etc.



. , , $_POST mysql_query. 99% , Composer, .., , , . .. - . Spring boot (java) : , .


, ?


β€” - (.. Golang ) . PHP β€” . , -, , , ..


-, . , . β€” . , , IDE , .


. , Collection , Collection<User>, .. "". .


PHP 8


. PHP8. , β€” JIT, .


JIT


. .. , , - , .


-? , … -, . , . , PHP . C, C++, Rust . .. PHP7.* PHP5 β€” . PHP , Ruby Python. PHP , - JIT PHP php-.


, , . - Async/await Promise.



PHP8? .
-, Symfony



    /**
     * @Route("/blog")
     */
    public function list()
    {
        // ...
    }

- :



    <<Route("/blog")>>
    public function list()
    {
        // ...
    }

, , . - , . . . , , .


Union Types mixed


, |


class Number {
    private int|float $number;

    public function setNumber(int|float $number): void {
        $this->number = $number;
    }

    public function getNumber(): int|float {
        return $this->number;
    }
}

. .


, PHP8 mixed .


Big deal? .


Weak maps


Weak maps β€” . ,



, - , . - .


, , .


-, PHP7.4 .



, β€” . :


PHP β€” () . , .


, β€” . PHP8 . , - nodejs/go .


" ", .


All Articles