-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StringHelper::truncate(null, 10) causes error - userland fix #19736
Comments
What it should return in case of |
I do have a draft with a Can we set the data type to |
If we add null check for convenience , shouldn't we add it everywhere where we denied change because the docs are not allowing null to be passed? |
May be empty string Not sure about going strict type. truncate expects string parameter. |
If truncate expects a string parameter shouldn't we enforce the type on the parameter? |
I would add the null-checks everywhere (since we cannot do the arguments type-forcing), I'm just mentioning that because we used to argue that since the docs are not allowing null (like with StringHelper::truncate) we should not do any checks and make it a developer's issue. |
Checking for nulls everywhere will make it compatible beyond 8.2, but the docs are based on when they were created, now the language is moving forward, adding more type checking and the framework needs to move along with the language. |
I agree that this is a developer issue - I just wanted the issue opened because the error was a little harder to troubleshoot between 8.0 and 8.1. Curious @bizley why type forcing can't be done on the arguments? |
It's because we are still supporting PHP 5.4. |
Accepting |
I prefer controlled flow. |
Any reason why |
Yes, for cases where an argument should be a string we could do that (and we do in many places). The null check should be for the multi-types arguments. |
I think this is same history in Yii2 Gii ActiveRecords model generator
|
@bizley Why? I think I know but would like to make sure. |
I think it was a promise made by the original team. |
https://github.com/yiisoft/yii2#installation
|
OK. Keeping promises is very good. But today 5.4 is dead: https://stitcher.io/blog/php-version-stats-january-2023 Do Yii2 team has any statistic how many installation (updates) is made from hosts with old PHP versions? |
Some stats: https://packagist.org/packages/yiisoft/yii2/php-stats If 5.4 is dropped an ie. 7.4 is the new minimum, I'd strongly advocate for a 2.1.0 version. |
PHP 7.0 might pass tests. |
|
For current code I'd add checks everywhere. |
As far as I know, With PHP 8.2 and JIT types will improve performance, before that it does not, and in many cases will be slower as it now has to type check. I am not entirely sure if PHP 8.2 brings those benefits. While I am for making PHP 8.x the minimum required version, its not like PHP 5.4 is not used. But these might be just automated testing systems. |
Let's continue discussion about 2.1 here #19831 Here let's focus on the issue only please. |
I did a fix: #19833 |
What steps will reproduce the problem?
Create a
StringHelper::truncate()
call to a null property. Quick note: I don't think that this is a framework issue and think it is more userland code but wanted to open the issue in case someone else receives the error.I solved it by wrapping the helper function in a userland check:
What is the expected result?
Was expecting an upgrade to 8.1 to go smoothly. I had to change a few things in the user code to make this work. Not sure if documentation should be updated to note this? If not feel free to close this issue.
What do you get instead?
Deprecated: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated
Additional info
Error:
The text was updated successfully, but these errors were encountered: