Is PHP Relevant In 2021?

The focus has long since moved from PHP to JavaScript and Python. Nevertheless, new versions are coming out, and the performance tests indicate good progress. How relevant is PHP today? Under the cut - the thoughts of the developer, who continues to give preference to him.





A brief history of PHP

PHP 1994 . , -, Personal Home Page Tools (ยซ ยป). PHP Tools. , : . .





, open source 1995 . , PHP.





โ€” PHP 8.0.





PHP?

โ€” . , . PHP , . , . 





, . :





echo "1" + 3;
echo 1 + "3";
echo "1" + "3";
      
      



4, . , , .





, .





PHP 5.3. , . - . 





, , Payments_Provider_Processor_Provider_SomeExternalServiceProvider



, SomeExternalServiceProvider



. .





.





, , . , , , . , , , . .





:





  • strpos(string $haystack, string $needle, int $offset = 0): int|false



    : ;





  • strsplit(string $string, int $length = 1): array



    : ;





  • explode(string $separator, string $string, int $limit = PHP_INT_MAX): array



    : .





: str



, str_



, . $string



str_split



, explode



. โ€” , .





โ€” , , . - , $SERVER



$REQUEST



. : . . , , .





PHP?

, . PHP 7 , , .





Type hints

PHP: type hints, , . :





function isValueSomething($value) {}
      
      



type hints, :





function isValueSomething(string $value): bool {}
      
      



, , -. , , type hints , IDE .





7.4 PHP :





class Person {
    public string $firstName;

    public string $lastName;

    public int $age;

    public ?string $job;
}
      
      



, Person



, integer . โ€” .





PHP :





  • : fn ($x, $y) => $x + $y;







  • : $value = $array['key'] ?? 'default value';







  • : return $cache['key'] ??= computeSomeValue('key');







  • : $first = ['a', 'b']; $second = ['c', 'd']; $final= [โ€ฆ$first, โ€ฆ$second];







  • : array_fill(start_index: 0, num: 100, value: 50);







  • : 299_792_458







.





Constructor promotion

Person



:





class Person {
    private string $firstName;

    private string $lastName; 

    protected int $age;

    public ?string $job;

    public function __construct(
        string $firstName,
        string $lastName,
        int $age,
        ?string $job
    ){
        $this->firstName = $firstName;
        $this->lastName = $lastName;
        $this->age = $age;
        $this->job = $job;
    }
}
      
      



PHP 8 :





class Person {
    public function __construct(
        private string $firstName,
        private string $lastName,
        protected int $age,
        public ?string $job
    ){}
}
      
      



, ?





Nullsafe-

JavaScript, PHP . , PHP:





<?
if (is_null($repository)) {
    $result = null;
} else {
    $user = $repository->getUser(5);
    if (is_null($user)) {
        $result = null;
    } else {
        $result = $user->name;
    }
}
      
      



PHP null. nullsafe- :





$result = $repository?->getUser(5)?->name;







?





, , type hints. . :





function doSomething(int|string $value): bool|array {}
      
      



, PHP , .





, PHP . , PHP 7 PHP 5.6, , . Phoronix , PHP 8 PHP 5.6. , .





Kinsta WordPress. WordPress 5.3.





:





  • WordPress 5.3 PHP 5.6: 97,71 /





  • WordPress 5.3 PHP 7.0: 256,81 /





  • WordPress 5.3 PHP 7.1: 256,99 /





  • WordPress 5.3 PHP 7.2: 273,07 /





  • WordPress 5.3 PHP 7.3: 305,59 /





  • WordPress 5.3 PHP 7.4: 313,42 /





PHP 8, , 7.4 5.6, .





PHP , . Golang, PHP Python, PHP, . , , PHP . 





, , -, , , open source.





, PHP , . , , , , .








All Articles