Some questions about literal-string #7238
Replies: 1 comment 6 replies
-
Hi @VincentLanglet, First some background... Unfortunately the PHP RFC for the is_literal() function failed. I will have another go, as I didn't receive any feedback that suggested it was wrong; e.g. a couple of people didn't want it to support string concatenation (on the basis that it could make mistakes easier to find; I disagree, I think tooling should do that, and this limitation would only make I'd also note the You can test the Ok, now to reply to your excellent points... With your first example, The main issue is that Yep, you are correct. If the library has a method with As to developers using I've got a few examples, but my Basic SQL library shows how a library could use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Since I tried to work on stub about literal-string, I have some questions @craigfrancis.
And since the
is_literal
is not working so far, I cannot try it.https://phpstan.org/r/499a50f0-3efa-4cee-ab55-24b2244ca0cb
In this example, I expect phpstan to report that the
assert(is_literal($text));
is always true.This can create some issue: If a library doesn't use a level of phpstan high enough (example with level 4: https://phpstan.org/r/cb2b9b60-5f48-4966-a893-f6fbb1b8a390) or if the setter is called in another library (so you cannot trust the value), the literal-string is considered as always true but isn't.
It could give a false feeling of security and people could remove some
is_literal
check which would have been useful.Another question I have with the literal-string, is about how it should be used by the developper.
For instance, if I have written something like
https://phpstan.org/r/458e9c61-a1be-4d48-8def-ed5c03cb29f8
I feel like my code is not so robust since a refacto of
You
class likehttps://phpstan.org/r/e50d8628-4894-4dfd-a361-50e3fbf73bff
could change my code so easily because I end in the else part instead of the if one.
With this example of how easily code could break when using some
is_literal
check, I don't feel safe using this method.Beta Was this translation helpful? Give feedback.
All reactions