Home  >  Q&A  >  body text

Why does the str_contain function in my PHP 7.4 project work properly?

As the title suggests, I'm developing a Symfony project using PHP 7.4, and I've been using the PHP function str_contains for a while now. However, while looking up some stuff today, I discovered 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 works fine, so my question (which may sound weird) is: why does my code work? Shouldn't it crash when I try to use the function?

P粉217629009P粉217629009238 days ago369

reply all(1)I'll reply

  • P粉801904089

    P粉8019040892024-01-30 10:31:08

    As suggested by @deceze and @u_mulder in the comments, it works thanks to the Symfony polyfill, which converts many functions, especially str_contains, from Backtracking in newer versions.

    reply
    0
  • Cancelreply