Problem/Motivation
Follow-up to issue #2931262: Replace intval(), strval(), .. *val() functions with their relevant type casting operators.
There are remaining usages of PHP 4-style type casting intval() in core/lib/Drupal/Core/Updater/Updater.php. We should consider converting those and remove the PHPCS ignore:
The use of function intval() is discouraged (Generic.PHP.ForbiddenFunctions.Discouraged)
Steps to reproduce
Grep for remaining usages:
[ayrton:drupal | Wed 04:38:58] $ grep -r "intval" * | grep -v "vendor" | grep -v "node_modules"
core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php: $ids = array_map('intval', $ids);
core/lib/Drupal/Core/Updater/Updater.php: $filetransfer->chmod($parent_dir, intval($old_perms, 8));
core/lib/Drupal/Core/Updater/Updater.php: $filetransfer->chmod($path, intval($new_perms, 8), $recursive);
core/phpcs.xml.dist: <element key="intval" value="null"/>
core/modules/language/src/LanguageNegotiator.php: $enabled_methods = array_map('intval', $enabled_methods);
core/modules/views/src/Plugin/views/HandlerBase.php: $value = array_map('intval', $value);
Remaining tasks
- Convert them with their relevant type casting operators
- Review
Comments
Comment #2
lucasscComment #3
prabuela commentedComment #4
prabuela commentedHi lucassc,
As the intval function is supported by php 8. Is there any particular reason to change the typecast methods.
Comment #5
prabuela commentedComment #6
lucasscHi, @PrabuEla!
Thanks for reply. You're right, it's optional to replace it nowadays but I think it's good to unify the way in core - as it was said in the parent issue.
I'm not sure about the performance improvement matter, but I think it might still be relevant?
Comment #9
harivansh commentedComment #10
smustgrave commentedIf it's just targeting that one file don't see an issue.
Comment #12
catchCommitted f9e91a8 and pushed to 10.1.x. Thanks!