PHP 8.6 chính thức ra mắt: Partial Function Application, clamp(), Time\Duration — bản nâng cấp lớn của PHP trong nămPHP 8.6 is officially out: Partial Function Application, clamp(), Time\Duration — PHP's big upgrade of the year
Mẹo: Dùng Microsoft Edge để nghe giọng đọc tiếng Việt tự nhiên hơn (HoaiMy, NamMinh).Tip: Use Microsoft Edge for more natural Vietnamese read-aloud voices (HoaiMy, NamMinh).

Sau 7 bản release candidate, PHP 8.6 đã chính thức phát hành ngày 19/11 — và đây không phải bản vá thường kỳ. Tính năng đáng chú ý nhất là Partial Function Application, viết lại cách dev PHP viết callback; cùng với đó là kiểu Duration chuẩn để đo thời gian, một API polling mới cho lập trình bất đồng bộ, và hàm `clamp()` mà gần như dev nào cũng từng tự viết lại bằng `min(max(...))`.After 7 release candidates, PHP 8.6 officially shipped on November 19 — and this is no routine patch. The headline feature is Partial Function Application, which rewrites how PHP developers write callbacks; alongside it come a standard Duration type for measuring time, a new polling API for async programming, and a `clamp()` function almost every developer has hand-rolled with `min(max(...))`.
Sau 7 bản release candidate, PHP 8.6 đã chính thức phát hành ngày 19/11 — và đây không phải bản vá thường kỳ. Tính năng đáng chú ý nhất là Partial Function Application, viết lại cách dev PHP viết callback; cùng với đó là kiểu Duration chuẩn để đo thời gian, một API polling mới cho lập trình bất đồng bộ, và hàm clamp() mà gần như dev nào cũng từng tự viết lại bằng min(max(...)).
Thông số nổi bật
| Tính năng | Nói ngắn gọn |
|---|---|
| Partial Function Application | Gọi hàm với một phần tham số, dùng ? làm chỗ giữ, nhận về một Closure chờ phần còn lại |
Time\Duration | Kiểu thời lượng chuẩn, chính xác tới nano giây, biểu diễn được hơn 250 năm — thay cho số micro giây rời rạc |
Polling API (Io\Poll) | Giám sát nhiều stream cùng lúc bằng epoll/kqueue/WSAPoll, nền tảng chung cho ReactPHP và AMPHP |
clamp() | Giữ một giá trị trong khoảng cho trước, dùng được với cả số lẫn Duration |
SortDirection enum | Cách chuẩn, type-safe để biểu diễn thứ tự sắp xếp, thay cho SORT_ASC/SORT_DESC rời rạc |
| Readonly property defaults | Thuộc tính readonly giờ khai báo được giá trị mặc định, không cần gán trong constructor |
| Xử lý lỗi stream mới | Lỗi stream thành StreamException/StreamError có cấu trúc, thay cho cảnh báo rời rạc |
#[\Override] cho hằng | Attribute này giờ dùng được cho class constant và enum case |
| Sodium hậu lượng tử | Thêm X-Wing và ML-KEM-768, mã hóa địa chỉ IP, hàm SHAKE và TurboSHAKE |
Điểm mới
Ngoài ra còn có Uri builders (Uri\Rfc3986\UriBuilder, Uri\WhatWg\UrlBuilder), DocComment riêng cho từng tham số hàm (đọc qua ReflectionParameter::getDocComment()), và thuộc tính của object trong hằng giờ sửa trực tiếp được (Config::DEFAULTS->timeout = 30).
Partial Function Application là thay đổi đáng viết code thử ngay. Trước đây, muốn cố định một phần tham số phải viết closure thủ công; giờ chỉ cần dấu ?:
$versions = ['8.4', '8.5', '8.6', '8.7', '9.0'];
// Trước 8.6: phải bọc bằng arrow function
$supportsPfa = array_filter(
$versions,
fn ($version) => version_compare($version, '8.6', '>='),
);
// PHP 8.6: dùng ? làm chỗ giữ cho tham số còn lại
$supportsPfa = array_filter(
$versions,
version_compare(?, '8.6', '>='),
);
Dấu ? cũng dùng được với tham số đặt tên, ví dụ backoff(..., attempt: ?) — hàm chỉ thực sự chạy khi Closure nhận đủ tham số còn lại.
Khác gì bản trước
PHP 8.5 (ra mắt năm ngoái) chủ yếu là bổ sung nhỏ; PHP 8.6 là bản phát hành lớn thường niên, thay đổi cả cách viết code hằng ngày lẫn nền tảng async. Ba điểm khác biệt thực chất nhất:
- PFA thay thế mẫu
fn (...) =>lặp đi lặp lại trong callback,array_map,array_filter— code ngắn hơn và đọc đúng ý đồ hơn. Time\Durationthay cho số nguyên micro giây trong timeout, backoff, benchmark — hết cảnh nhầm đơn vị giây/mili/micro giây.Io\Pollthay chostream_select()vốn giới hạn khoảng 1.024 kết nối — mở đường cho server PHP xử lý nhiều kết nối đồng thời hơn mà không cần extension ngoài.
Về quy mô thay đổi: bản này thêm 17 hàm, 24 class, 15 enum, 47 hằng và 1 interface mới; đồng thời deprecated 26 hàm và 2 hằng, gỡ bỏ 2 extension, 15 hàm và 2 class. Nghĩa là dự án cũ nâng cấp lên 8.6 gần như chắc chắn sẽ gặp cảnh báo deprecated cần dọn.
Giá và thời điểm dùng được
PHP 8.6.0 đã tải được ngay từ php.net từ ngày 19/11, miễn phí và mã nguồn mở như mọi bản PHP. Theo chu kỳ hỗ trợ chuẩn của PHP, bản này dự kiến được hỗ trợ tới cuối 2028 và vá bảo mật tới cuối 2030. Lưu ý: PHP 8.6 ra mắt cùng ngày với loạt bản vá bảo mật 8.2.36, 8.3.37, 8.4.28 và 8.5.13 (17 CVE, trong đó 7 critical) — những bản vá này đã được cảnh báo tối 19/11, và nếu bạn chưa lên 8.6 thì cập nhật bản vá cho nhánh đang chạy trước đã.
Ai nên thử
Mọi dev PHP, đặc biệt team đang chạy Laravel, Symfony hoặc WordPress — nhưng theo hướng thử nghiệm có kiểm soát: chạy test suite trên PHP 8.6 trong CI trước, quét deprecation, rồi mới tính chuyện đưa lên staging. Các thư viện async như ReactPHP và AMPHP sẽ là bên hưởng lợi trực tiếp từ Io\Poll, nên team làm realtime/websocket nên theo dõi các bản cập nhật của chúng trong vài tuần tới.
Việc cần làm 1. Chạy test suite trên PHP 8.6 trong CI (để chế độ allowed-to-fail trước) để thấy deprecation và lỗi tương thích trước khi nâng cấp thật. 2. Quét danh sách deprecated: 26 hàm và 2 hằng bị deprecated, 2 extension và 15 hàm bị gỡ — sửa trước khi lên production. 3. Nếu chưa lên 8.6: cập nhật ngay bản vá bảo mật ngày 19/11 cho nhánh đang chạy (8.2.36 / 8.3.37 / 8.4.28 / 8.5.13) — đừng đợi nâng cấp lớn mới vá. 4. Đọc migration guide trên php.net trước khi nâng cấp production, đặc biệt phần thay đổi hành vi mặc định của session và stream.
*Nguồn: https://www.php.net/releases/8.6/en.php*
After 7 release candidates, PHP 8.6 officially shipped on November 19 — and this is no routine patch release. The most notable feature is Partial Function Application, which rewrites how PHP developers write callbacks; alongside it come a standard Duration type for measuring time, a new polling API for asynchronous programming, and a clamp() function that almost every developer has hand-rolled at some point with min(max(...)).
Key specs
| Feature | In short |
|---|---|
| Partial Function Application | Call a function with part of its arguments, using ? as a placeholder, and get back a Closure waiting for the rest |
Time\Duration | A standard duration type, precise to the nanosecond, able to represent more than 250 years — replacing scattered microsecond numbers |
Polling API (Io\Poll) | Monitor many streams at once using epoll/kqueue/WSAPoll, a common foundation for ReactPHP and AMPHP |
clamp() | Keep a value within a given range, usable with both numbers and Duration |
SortDirection enum | A standard, type-safe way to express sort order, replacing scattered SORT_ASC/SORT_DESC |
| Readonly property defaults | Readonly properties can now declare a default value, with no need to assign them in the constructor |
| New stream error handling | Stream errors become structured StreamException/StreamError, replacing scattered warnings |
#[\Override] for constants | This attribute can now be used for class constants and enum cases |
| Post-quantum Sodium | Adds X-Wing and ML-KEM-768, IP address encryption, and the SHAKE and TurboSHAKE functions |
What's new
There are also Uri builders (Uri\Rfc3986\UriBuilder, Uri\WhatWg\UrlBuilder), a separate DocComment for each function parameter (read via ReflectionParameter::getDocComment()), and object properties in constants can now be modified directly (Config::DEFAULTS->timeout = 30).
Partial Function Application is the change worth trying in code right away. Previously, fixing part of the arguments meant writing a manual closure; now all it takes is the ?:
$versions = ['8.4', '8.5', '8.6', '8.7', '9.0'];
// Before 8.6: had to wrap in an arrow function
$supportsPfa = array_filter(
$versions,
fn ($version) => version_compare($version, '8.6', '>='),
);
// PHP 8.6: use ? as a placeholder for the remaining argument
$supportsPfa = array_filter(
$versions,
version_compare(?, '8.6', '>='),
);
The ? also works with named arguments, e.g. backoff(..., attempt: ?) — the function only actually runs once the Closure receives all the remaining arguments.
What changed vs the previous version
PHP 8.5 (released last year) was mostly small additions; PHP 8.6 is the big annual release, changing both everyday coding habits and the async foundation. The three most substantive differences:
- PFA replaces the repetitive
fn (...) =>pattern in callbacks,array_map,array_filter— code is shorter and reads closer to its intent. Time\Durationreplaces integer microseconds in timeouts, backoff, benchmarks — no more second/millisecond/microsecond unit mix-ups.Io\Pollreplacesstream_select(), which is limited to about 1,024 connections — paving the way for PHP servers to handle more concurrent connections without external extensions.
On the scale of change: this release adds 17 new functions, 24 classes, 15 enums, 47 constants and 1 interface; at the same time it deprecates 26 functions and 2 constants, and removes 2 extensions, 15 functions and 2 classes. That means an old project upgrading to 8.6 will almost certainly hit deprecation warnings that need cleaning up.
Price and availability
PHP 8.6.0 has been downloadable from php.net since November 19, free and open source like every PHP release. Under PHP's standard support cycle, this release is expected to be supported until the end of 2028 and receive security patches until the end of 2030. Note: PHP 8.6 launched on the same day as the series of security patches 8.2.36, 8.3.37, 8.4.28 and 8.5.13 (17 CVEs, 7 of them critical) — those patches were flagged on the evening of November 19, and if you are not moving to 8.6 yet, update the patch for the branch you are running first.
Who should try it
Every PHP developer, especially teams running Laravel, Symfony or WordPress — but in a controlled, experimental way: run the test suite on PHP 8.6 in CI first, scan the deprecations, and only then think about moving to staging. Async libraries such as ReactPHP and AMPHP will benefit directly from Io\Poll, so teams doing realtime/websocket work should watch their updates over the coming weeks.
What to do 1. Run your test suite on PHP 8.6 in CI (in allowed-to-fail mode first) to surface deprecations and compatibility errors before a real upgrade. 2. Scan the deprecation list: 26 functions and 2 constants are deprecated, 2 extensions and 15 functions removed — fix them before going to production. 3. If you are not on 8.6 yet: update the November 19 security patch for the branch you are running right away (8.2.36 / 8.3.37 / 8.4.28 / 8.5.13) — do not wait for the big upgrade to patch. 4. Read the migration guide on php.net before upgrading production, especially the section on changed default behaviour for sessions and streams.
*Source: https://www.php.net/releases/8.6/en.php*
Nguồn tham chiếuSource: php.net


