PHP 8.0 เปิดตัว
(php.net)-
ปรับปรุงความเร็วด้วย JIT engine สองตัว: Tracing JIT + Function JIT
-
ปรับปรุงระบบ type และการจัดการข้อผิดพลาด
-
Named arguments
→ htmlspecialchars($string, double_encode: false);
- Attributes
→ #[Route("/api/posts/{id}", methods: ["GET"])]
- Constructor property promotion
→ __construct( public float $x = 0.0 ) {}
- Union Type
→ private int|float $number
- Match expression
→ match (8.0) { '8.0' => "Oh no!", 8.0 => "This is what I expected", };
- Nullsafe operator
→ $country = $session?->user?->getAddress()?->country;
- การเปรียบเทียบ string กับ number ที่สมเหตุสมผลขึ้น
→ 0 == 'foobar' // false (เมื่อก่อนเป็น true)
- เพิ่มเติม: คลาส WeakMap, อินเทอร์เฟซ Stringable, และฟังก์ชัน str_contains(), str_starts_with(), str_ends_with()
2 ความคิดเห็น
ตอนนี้
empty("0") => trueแต่ในเวอร์ชัน 8 จะเป็นอย่างไร?!ใน 8 ก็ยังเหมือนเดิมเลย 55