Ist PHP im Jahr 2021 relevant?

Der Fokus hat sich längst von PHP auf JavaScript und Python verlagert. Trotzdem kommen neue Versionen heraus und die Leistungstests zeigen gute Fortschritte. Wie relevant ist PHP heute? Unter dem Schnitt - die Gedanken des Entwicklers, der ihm weiterhin den Vorzug gibt.





Eine kurze Geschichte von 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