phpphp-7.4php-8

Why does str_contains work in my Symfony project with PHP 7.4?


As title suggests, I am working on a Symfony project with PHP 7.4 and I have been using the PHP function str_contains for a while now. However today looking something up I found that this function was introduced in PHP 8.0, as explained here: https://php.watch/versions/8.0/str_contains

In my project, str_contains is working fine, so my question (as weird as it may sound) is: how can my code be working? Shouldn't it crash when I try to use that function?


Solution

  • As it has been suggested in the comments by @deceze and @u_mulder, it works thanks to Symfony polyfill, which backports many functions, in particular str_contains, from newer versions.