yii2: StringHelper::truncate(null, 10) causes error - userland fix
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:
yii\base\ErrorException: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /app/vendor/yiisoft/yii2/helpers/BaseStringHelper.php:132
Q | A |
---|---|
Yii version | 2.0.47 |
PHP version | 8.1 |
Operating system | Docker yii2 container |
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 26 (23 by maintainers)
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.
Let’s continue discussion about 2.1 here https://github.com/yiisoft/yii2/discussions/19831
Here let’s focus on the issue only please.
It’s because we are still supporting PHP 5.4.