Closed caiojhonny closed 1 year ago
Why are you assigning the result of
array_key_exists()
tomonth
field?
Because there is no verification of the key into tabDecodeMonths and a warning is generated: Undefined array key "G" in vendor/robertogallea/laravel-codicefiscale/src/CodiceFiscale.php on line 179.
Can you try to reproduce the same error using this codice fiscale: GNIWCF85G08P870X?
Thanks
Ok, but since array_key_exists() always returns a boolean, the right term of null coalescing operator will never be evaluated and month will always be assigned with either true or false, never a number. Am I missing something?
Il mar 13 giu 2023, 17:34 Caio Jhonny @.***> ha scritto:
Why are you assigning the result of array_key_exists() to month field?
Because there is no verification of the key into tabDecodeMonths and a warning is generated: Undefined array key "G" in vendor/robertogallea/laravel-codicefiscale/src/CodiceFiscale.php on line 179.
Can you try to reproduce the same error using this codice fiscale: GNIWCF85G08P870X?
Thanks
— Reply to this email directly, view it on GitHub https://github.com/robertogallea/laravel-codicefiscale/pull/56#issuecomment-1589553800, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEUDEDWGBCH2KQGLGD2J5C3XLCCB5ANCNFSM6AAAAAAZDLF6DI . You are receiving this because you commented.Message ID: @.***>
You right, sorry for that.
I corrected my file.
The logic is: If the key exists on array "$this->tabDecodeMonths", proceed, if not is null.
This prevents the warning.
Thanks
Sure, I got that, but was wondering if I was missing something in your syntax. 😉
Thanks!
Would you mind extracting a variable for the repetition in substr(...)?
Thanks!
Done. Thanks!
That's it! Thank you!
Prevent warning: Undefined array key "G" in vendor/robertogallea/laravel-codicefiscale/src/CodiceFiscale.php on line 179.
Codice Fiscale Value used for tests: GNIWCF85G08P870X
Description
Preventing warning "Undefined array key" using value: GNIWCF85G08P870X
Types of changes
What types of changes does your code introduce? Put an
x
in all the boxes that apply: