New in Symfony Polyfills 1.15
Symfony Polyfills provide PHP implementations of certain PHP features so you can use them even if you don't have the right PHP version or PHP extension installed. Symfony Polyfill 1.15 was released recently and these are the most important changes.
PHP 8 polyfill improvements¶
PHP 8.0, the next major PHP version stated for release on December 3, 2020, will add some interesting features. Some of them have already been added to Symfony PHP 8 polyfill, so you can start using them today regardless of your PHP version.
Stringable is a new PHP interface that is added automatically to any object
It can be used to state that you accept both strings and objects that can be
converted into strings. In PHP 8 you can do that for example with the following
Read more about this interface in the Stringable PHP RFC.
get_debug_type() function returns the given type of a variable.
It's useful to simplify the code that required using
gettype() to get the type of some variable:
1 2 3 4 5
// Before throw new TypeError('Expected '.Foo::class.' got '.(is_object($bar) ? get_class($bar) : gettype($bar))); // After throw new TypeError('Expected '.Foo::class.' got '.get_debug_type($bar));
Read more about this function in the get_debug_type() PHP RFC.
str_contains() function checks if a string is contained in another
string and returns a boolean value (true/false) whether or not the string was found.
This function can replace
strstr() which are often used for
the same purpose but require code which sometimes is not very intuitive.
Read more about this function in the str_contains() PHP RFC.
preg_last_error_msg() function returns a human-friendly string
representation of the last PCRE regular expression execution error.
In previous PHP versions, you had to convert the error code returned by
preg_last_error() into a meaningful error message.
UUID polyfill improvements¶
In addition, we added support for UUID on 32-bit systems to make the polyfill truly portable.
Fixed PHP preloading¶
PHP preloading is one of the most important new features introduced in PHP 7.4. This feature allows loading some functions/classes in memory to make them available to all requests, improving the application performance.
In Symfony Polyfill 1.15 we fixed some issues to make sure all polyfills are compatible with PHP preloading.
Become a certified developer! Exams are online and available in all countries.Register Now
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.