Share
Embed
What's new in PHP 8.3
Christian Leo-Pernold
February 22, 2024
Transcript
54 slides
-
About me — ! Christian Leo-Pernold — "#$%&'()*⛰,-. — /
@[email protected] — ⭐ github.com/mazedlx — 1 mazedlx.net — 2 https://www.linkedin.com/in/ mazedlx 2/54 -
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 -
PHP 8.3 was released on 2023-11-23 will reach EOL on
2025-11-23 4/54 -
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 -
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 -
$array = []; $array[-5] = 'a'; $array[] = 'b'; //
Pre 8.3 [ -5 => 'a', 0 => 'b' ] // 8.3 [ -5 => 'a', -4 => 'b', ] 13/54 -
$class = new readonly class { public function __construct( public
string $foo = 'bar', ) {} }; 15/54 -
class Foo { const BAR = 'bar'; } $name =
'BAR'; // Instead of this: constant(Foo::class . '::' . $name); // You can now do this: Foo::{$name}; 23/54 -
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 -
unserialize() will now always emit a E_WARNING when running into
problems instead of sometimes an E_NOTICE. 27/54 -
— 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 -
— 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 -
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 -
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 -
PHP 8.3 adds two new ini directives called zend.max_allowed_stack_size and
zend.reserved_stack_size. 35/54 -
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 -
function mb_str_pad( string $string, int $length, string $pad_string = "
", int $pad_type = STR_PAD_RIGHT, ?string $encoding = null, ): string {} 38/54 -
class Test { public function __call($name, $args) { var_dump($name, $args);
} public static function __callStatic($name, $args) { var_dump($name, $args); } } 40/54 -
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 -
— 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 -
— 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 -
— 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 -
— 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 -
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 -
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