On Sun, 13 Jun 2021 at 20:33, someniatko wrote:
[...] Have you considered [a] new `literal-string` type, which would be
enforced by PHP all the time?


Thanks someniatko, a "clearer intent" is a really nice way of putting it.

It is something that Joe is considering, but for a future version,
simply because it will require more discussion (which I'm happy to help
with).

And I agree, there would be value in having a `literal-string` type,
especially when working with IDE's and Static Analysers; but it brings a
couple of issues that the is_literal() function solves:

1) Libraries need to support older versions of PHP, so they wouldn't be
able to use the `literal-string` for many years; whereas they can use
`function_exists('is_literal')` today, probably to provide their own
function that simply returns true on pre PHP 8.1.

2) The is_literal() function gives the libraries a choice on how to handle
the situation. At the moment they just receive a string of unknown origin,
so they can trigger a warning, while also supporting legacy projects who
want to switch off the warnings. And some developers might want to use a
library that has an option that can raise exceptions (so they can be
certain there are no issues).

Craig

Reply via email to