Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's new in PHP 8.3

What's new in PHP 8.3

Christian Leo-Pernold

February 22, 2024
Tweet

More Decks by Christian Leo-Pernold

Other Decks in Technology

Transcript

  1. About me — ! Christian Leo-Pernold — "#$%&'()*⛰,-. — /

    @[email protected] — ⭐ github.com/mazedlx — 1 mazedlx.net — 2 https://www.linkedin.com/in/ mazedlx 2/54
  2. Version History and EOL 1,2 5.6 2018-12-31 (5 years ago)

    7.0 2019-01-19 (5 years ago) 7.1 2019-12-31 (4 years ago) 7.2 2020-11-30 (3 years ago) 7.3 2021-12-06 (2 years ago) 7.4 2022-11-28 (1 year ago) 8.0 2023-11-26 (2 months ago) 8.1 2023-11-25 (2 months ago) 8.2 2024-12-08 (9 months from now) 1,2 https://www.php.net/supported-versions.php and https://www.php.net/eol.php 3/54
  3. readonly class Post { public function __construct( public DateTime $createdAt,

    ) {} public function __clone() { $this->createdAt = new DateTime(); // This is allowed, // even though `createdAt` is a readonly property. } } 7/54
  4. abstract class Parent { public function methodWithDefaultImplementation(): int { return

    1; } } final class Child extends Parent { #[Override] public function methodWithDefaultImplementation(): int { return 2; // The overridden method } } y 11/54
  5. $array = []; $array[-5] = 'a'; $array[] = 'b'; //

    Pre 8.3 [ -5 => 'a', 0 => 'b' ] // 8.3 [ -5 => 'a', -4 => 'b', ] 13/54
  6. class Foo { const BAR = 'bar'; } $name =

    'BAR'; // Instead of this: constant(Foo::class . '::' . $name); // You can now do this: Foo::{$name}; 23/54
  7. DateRangeError: // Epoch doesn't fit in a PHP integer DateMalformedIntervalStringException

    // Only non-special relative time specifications are supported for subtraction DateInvalidOperationException // String '%s' contains non-relative elements 25/54
  8. unserialize() will now always emit a E_WARNING when running into

    problems instead of sometimes an E_NOTICE. 27/54
  9. — TypeError when passing objects, resources, or arrays as the

    boundary inputs — ValueError — when passing 0 as $step — when using a negative $step for increasing ranges 29/54
  10. — E_WARNING — when $start or $end is an empty

    string — when $start or $end is a non-numeric string and greater than 1 byte (e.g. 'aa') — when the type of $start and $end differ (e.g. range(1, 'z')) — when $step is a float and the boundaries are non- numeric strings (e.g. range('a', 'b', 0.5)) 30/54
  11. range() produces a list of characters, if one boundary is

    a string digit instead of casting the other input to int (e.g. range('8', 'c')) [ 0 => "8", 1 => "9", 2 => ":", 3 => ";", ... 8 => "@", 9 => "A", 10 => "B", ... 33 => "Y", 34 => "Z", 35 => "[", ... 41 => "a", 42 => "b", 43 => "c", ] 31/54
  12. From the changelog[^3](https://www.php.net/manual/en/ migration83.incompatible.php): Uses of traits with static properties

    will now redeclare static properties inherited from the parent class. This will create a separate static property storage for the current class. This is analogous to adding the static property to the class directly without traits. 33/54
  13. Programs that are close to overflowing the call stack may

    now throw an Error when using more than the difference between zend.max_allowed_stack_size and zend.reserved_stack_size. 36/54
  14. function mb_str_pad( string $string, int $length, string $pad_string = "

    ", int $pad_type = STR_PAD_RIGHT, ?string $encoding = null, ): string {} 38/54
  15. class Test { public function __call($name, $args) { var_dump($name, $args);

    } public static function __callStatic($name, $args) { var_dump($name, $args); } } 40/54
  16. interface I { public const FOO = 'foo'; } class

    C implements I { private const FOO = 'foo'; } // PHP Fatal error: Access level to C::FOO must be public (as in interface I) 43/54
  17. — Deprecate passing negative $widths to mb_strimwidth() — Deprecate and

    remove the NumberFormatter::TYPE_CURRENCY constant — Deprecate and remove the broken pre-PHP 7.1 Mt19937 implementation (MT_RAND_PHP) — Deprecate and remove calling ldap_connect() with 2 parameters $host and $port — Deprecate remains of string evaluated code assertions [^4](https://wiki.php.net/rfc/assert-string-eval- cleanup) 45/54
  18. — When using FFI5, C functions that have a return

    type of void now return null instead of returning FFI\CData:void — posix_getrlimit() now takes an optional $res parameter to allow fetching a single resource limit. — gc_status() has four new fields: running, protected, full, and buffer_size. — get_class() and get_parent_class() function calls without arguments are now deprecated 5 Foreign function interface, allows us to call C code from userland 47/54
  19. — class_alias() now supports creating an alias of an internal

    class. — mysqli_poll() now raises a ValueError when the read nor error arguments are passed. — array_pad() is now only limited by the maximum number of elements an array can have. Before, it was only possible to add at most 1.048.576 elements at a time. 48/54
  20. — New posix functions: posix_sysconf(), posix_pathconf(), posix_fpathconf(), and posix_eaccess() —

    Executing proc_get_status() multiple times will now always return the right value on posix systems. — opcache.consistency_checks ini directive was removed — Improved array_sum() and array_product()[^6](https:// wiki.php.net/rfc/saner-array-sum-product) 49/54
  21. highlight_file and highlight_string output HTML is now wrapped within <pre><code></code></pre>

    tags, and new- line characters are no longer convertes to <br /> php -l can now lint multiple files at once 51/54
  22. Where to go from here? — Read the blog post

    https://stitcher.io/blog/new-in- php-83 — Also https://php.watch/versions/8.3 — Follow @brendtgd on Twitter <https://twitter.com/ brendtgd> (or don't if you don't like Elon) — Download PHP 8.3 now! 52/54