Skip to content
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

Deprecation warning when trying to trans() with a null value in replacements #42204

Closed
oprypkhantc opened this issue Apr 30, 2022 · 1 comment

Comments

@oprypkhantc
Copy link
Contributor

  • Laravel Version: 9.10.0
  • PHP Version: 8.1.5

Description:

Trying to feed trans() a second argument that is an array with a key and a null value results in a deprecation warning:
local.WARNING: ErrorException: mb_substr(): Passing null to parameter #1 ($string) of type string is deprecated in /app/vendor/laravel/framework/src/Illuminate/Support/Str.php:941

While that case isn't described in the Laravel documentation, it used to work and still does. I also believe it's reasonably common to occur, especially when just feeding the values from the database into the translator.

Steps To Reproduce:

  1. Configure the deprecations log as per docs
  2. Run the following:
trans('validation.after', [
	'date' => null,
]);
  1. See a deprecation warning:
[2022-04-30 20:42:31] local.WARNING: ErrorException: mb_substr(): Passing null to parameter #1 ($string) of type string is deprecated in /app/vendor/laravel/framework/src/Illuminate/Support/Str.php:941
Stack trace:
#0 /app/vendor/laravel/framework/src/Illuminate/Support/helpers.php(418): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()
#1 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(106): with()
#2 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(71): Illuminate\Foundation\Bootstrap\HandleExceptions->handleDeprecation()
#3 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(229): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#4 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()
#5 /app/vendor/laravel/framework/src/Illuminate/Support/Str.php(941): mb_substr()
#6 /app/vendor/laravel/framework/src/Illuminate/Support/Str.php(1011): Illuminate\Support\Str::substr()
#7 /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php(220): Illuminate\Support\Str::ucfirst()
#8 /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php(194): Illuminate\Translation\Translator->makeReplacements()
#9 /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php(124): Illuminate\Translation\Translator->getLine()
@driesvints
Copy link
Member

Thanks for reporting this. I've sent in a PR for this: #42216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants