Problem/Motivation
After upgrading to PHP 8.0.21 Webform blows up with the error message
TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in abs() (line 766 of /local/drupal/sites/all/modules/webform/components/number.inc
Worked with earlier versions of PHP.
Steps to reproduce
- Install webform 7.x-4.24 on a Drupal 7 site
- upgrade PHP to 8.0.21
- create a form with a number field
- try to bring up the form
- note the error message
Proposed resolution
--- number.inc 2021-04-07 13:07:13.000000000 -0400
+++ /tmp/number.inc 2022-08-01 09:34:28.961992579 -0400
@@ -763,7 +763,7 @@
*/
function _webform_number_select_options($component) {
$options = array();
- $step = abs($component['extra']['step']);
+ $step = abs($component['extra']['step'] ?: 1);
// Step is optional and defaults to 1.
$step = empty($step) ? 1 : $step;
Remaining tasks
Apply patch.
User interface changes
None.
API changes
N/A
Data model changes
None
Comments
Comment #2
bklineComment #4
immaculatexavier commentedCommitted in accordance to the proposed resolution. please review
Comment #5
bklineWorks in my environment.
Comment #6
ccarnnia commentedThank you @immaculatexavier .
This worked for webform 7.x-4.24 on 7.91 core with php 8.0.17.
Exported it as a patch while we wait for the MR.
Comment #7
liam morlandThanks. Please make a merge request.
It would be great for a test to be added which would surface this.
Comment #8
solideogloria commentedThis isn't the best solution. Look at the next line:
Perhaps the line
$step = empty($step) ? 1 : $step;should come first, instead of adding?: 1This issue happens when step isn't set in the options, which makes the
$component['extra']['step']empty string. Switching the line order should fix it.Alternatively, remove the second line and use
$step = abs($component['extra']['step'] ?: 1);Comment #10
solideogloria commentedComment #11
solideogloria commentedI confirmed it fixes the issue for me. This is just an improved version, so should be a quick RTBC.
Comment #12
bklineLooks good to me.
Comment #13
solideogloria commentedI'm marking this issue major, as it prevented users from submitting certain webforms after I switched to PHP 8.
Comment #15
liam morlandThanks everyone!