class Number {
private int|float $number;
public function setNumber(int|float $number): void {
$this->number = $number;
}
public function getNumber(): int|float {
return $this->number;
}
}
在Zinc Prod播客的其中一个问题中,我们简要讨论了PHP8中的新增功能。录制后,我决定写一篇文章,阐述我对PHP在现代开发中的地位的看法。
让我们总体上确定该语言所占据/占据的位置以及它所处的位置
最初,该语言被定位为一种简单的工具,该工具开箱即用地具有Web所需的一切。
一方面,这是事实:例如,没有其他库,您可以从超全局变量$ _POST中提取POST请求参数,然后使用内置函数将其插入mysql,这似乎很棒。
同样重要的是,“生而死”模型(例如,在php-fpm中)被简化并简化了疯狂的开发过程:您不需要知道什么锁,死锁,内存泄漏等。无需在每行代码等之前写等待。
该脚本开始处理传入的HTTP请求,在没有与任何人交谈的情况下在单独的进程中工作,然后终止,清除了所有内容。很容易编程。进入阈值接近零。
, : — .
, , . .
: , , 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
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 .
" ", .