User tests: Successful: Unsuccessful:
Pull Request for Issue #38510 .
If $path is null, it will get '' value instead of run trim() function.
use Joomla\CMS\Filesystem\Path;
echo Path::clean(null);
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /{root}/libraries/src/Filesystem/Path.php on line 198
Warning disappear
No
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
I agree I would say we should not pass an empty string to that method in the first place.
Think we need some more info here because the is_string call immediately above this line should fail before you've reached the trim
If $path = NULL
it will pass if (!\is_string($path) && !empty($path)) {
I test in my local with var_dump
var_dump($path, is_string($path), empty($path));
Result Below
Yes thats the reason I would not like to add that if else catch in every method that is handeling strings and hide the issues of passing null or empty strings to methods which should not be called with empty strings in the first place.
Labels |
Added:
?
|
Category | Libraries | ⇒ | Layout Libraries |
Yes thats the reason I would not like to add that if else catch in every method that is handeling strings and hide the issues of passing null or empty strings to methods which should not be called with empty strings in the first place.
Yeah! I fixed it in my component. Anyway, I think other extensions will face that when customer update PHP to 8.1
yes when the extension is ready for 8.1 that message does not come up right? When it is not ready for 8.1 yet the issue should be reported to the developer so it can be fixed right? Right now its not an fatal error by php yet anyway so "hiding" error messages "hides" the issue in the same way but allows the developer to find and fix it too.
Maybe the
if (!\is_string($path) && !empty($path)) {
should be changed to something like
if ($path === null || (!\is_string($path) && !empty($path))) {
?
As long as a library accepts null values is should work properly and not throw different errors on different PHP versions. So making a change in the library is fine.
Category | Libraries Layout | ⇒ | Libraries |
Maybe the
if (!\is_string($path) && !empty($path)) {
should be changed to something likeif ($path === null || (!\is_string($path) && !empty($path))) {
?
You are right! I updated code with if ($path === null || (!\is_string($path) && !empty($path))) {
Best Regards,
This is now a BC break as an exception is thrown when the path is null, which wasn't before.
This is now a BC break as an exception is thrown when the path is null, which wasn't before.
May you me give a suggestion? Raise an exception
to force developer fix in their code or set $path = ''
to ignore it. I'm wondering about that.
Thanks & Best Regards,
I would go with something like:
if ($path === null) {
@trigger_error(
sprintf(
'Path can not be null, in 5.0 it will throw an exception',
__METHOD__
),
E_USER_DEPRECATED
);
$path = '';
}
Labels |
Added:
PHP 8.x
|
Looks correct now. Thanks!
When you update the test instructions and expected/actual result the way, that the testers know what to do, then it is very likely that you change gets merged. You can put something like in testing instructions with some files in core:
Similar to what I did in #38535.
I have tested this item
Labels |
Added:
Maintainers Checked
|
I have tested this item
@alikon , can you please retest since a change was made?
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
This has to go into 4.3 as it adds a deprecation. So waiting for the upmerge to make a rebase.
Title |
|
Labels |
Added:
?
PR-4.3-dev
|
PR for manual can be found here joomla/Manual#33.
Labels |
Added:
Information Required
|
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-09-04 14:59:27 |
Closed_By | ⇒ | obuisard | |
Labels |
Removed:
?
|
Thank you all for working on this issue!
Think we need some more info here because the is_string call immediately above this line should fail before you've reached the trim