Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
PHP 7.1 introduced Warning about invalid strings in arithmetic. And, yes, there is such "dirty" code in Drupal\Core\Menu\LocalTaskManager->getDefinitions() on line 187 ($definition['weight'] contains numeric string):
public function getDefinitions() {
$definitions = parent::getDefinitions();
$count = 0;
foreach ($definitions as &$definition) {
if (isset($definition['weight'])) {
// Add some micro weight.
$definition['weight'] += $count++ * 1.0E-6;
}
}
return $definitions;
}
This is throwing errors on every page load and flooding my database with them!
Also makes the error-log unreadable.
Caused by a typo in a custom_module.links.task.yml file
I put a ;
after weight: 10
weight: 10;
Comments
Comment #2
Pascal- CreditAttribution: Pascal- commentedComment #4
Pascal- CreditAttribution: Pascal- commentedAfter looking through core/lib/Drupal/Core/Menu/LocalTaskManager.php I feel like one of my menu's is causing this, though I'm not sure.
I have no idea where to start looking ...
Comment #5
Pascal- CreditAttribution: Pascal- commentedThis was caused by a typo in a custom_module.links.task.yml file
I put a
;
afterweight: 10
weight: 10;
Comment #6
Pascal- CreditAttribution: Pascal- commentedComment #7
Pascal- CreditAttribution: Pascal- commentedWould a patch for core/lib/Drupal/Core/Menu/LocalTaskManager.php to check if the value is numeric be enough to solve this?
Also what kind of error should it show / throw / return? (Haven't done any core contrib so far)
Or is this a deeper issue?
Comment #8
BerdirEither we just cast it to int/float or could do an assert() that it is not a string.
Comment #9
lalit774 CreditAttribution: lalit774 as a volunteer commentedComment #10
lalit774 CreditAttribution: lalit774 as a volunteer commentedComment #12
littlepixiez CreditAttribution: littlepixiez as a volunteer and commented#9 fixes it for me (PHP 7.2).
Comment #13
Liam MorlandComment #20
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
With Drupal 9.4 dropping php7.3 and D10 requiring php8.1 wonder if this is still an issue? Could someone please confirm
Comment #21
quietone CreditAttribution: quietone at PreviousNext commentedThanks for the report and working to improve Drupal.
There has been no discussion of the problem here for 5 years. As #20 points out, we dropped support for PHP 7.1 some time ago. Therefor, I am closing this as outdated.
Thanks