Problem/Motivation

Deprecated function: strcasecmp(): Passing null to parameter #1 ($string1) of type string is deprecated in webform_conditional_operator_string_equal() (line 1548 of .../webform/includes/webform.conditionals.inc).

Steps to reproduce

function webform_conditional_operator_string_equal($input_values, $rule_value) {
  foreach ($input_values as $value) {
    // Checkbox values come in as 0 integers for unchecked boxes.
    $value = ($value === 0) ? '' : $value;
    if (strcasecmp($value, $rule_value) === 0) {
      return TRUE;
    }
  }
  return FALSE;
}

The assertion Checkbox values come in as 0 integers for unchecked boxes. is not entirely complete. For radio buttons, if none of the options are selected, the value sent is NULL, not zero.

Proposed resolution

Instead of

$value = ($value === 0) ? '' : $value;

Use this:

$value = ($value === 0 || $value === NULL) ? '' : $value;

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork webform-3324874

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

solideogloria created an issue. See original summary.

solideogloria’s picture

Status: Active » Needs review
joseph.olstad’s picture

hmm, very strange as to why there's 10 fails, perhaps an upstream issue, perhaps need a no_change patch to test against to kick HEAD around.

liam morland’s picture

Is there a reason not to use empty()?

The test failure is likely due to #3194156: Patches and Merge Requests lead to different test results. Unfortunately, getting tests to pass often requires uploading a patch.

solideogloria’s picture

'0' is empty but should not return an empty string. Honestly, I think use of the empty() function should be avoided in most cases due to its weird behavior.

solideogloria’s picture

StatusFileSize
new1.09 KB

This is the patch from the MR

liam morland’s picture

Status: Needs review » Fixed

Thanks!

poker10’s picture

Thanks @Liam Morland! Would it be possible to publish a new 7.x-4.x release with all these PHP 8 compability fixes sometime soon?

joseph.olstad’s picture

StatusFileSize
new48.99 KB

Yes nicely done @Liam Morland, please tag and push a new release with these fixes.
php 8.2 passing on dev branches

joseph.olstad’s picture

Also, I recommend setting PHP 8.2 as the issue testing default.

liam morland’s picture

I'm just waiting for 2 weeks to pass since the last issue was marked fixed. Two more days.

I plan to upgrade the default testing PHP version once 8.2 is more widely used and I can be more confident there will not be regressions in compatibility. Currently, D7 core is not automatically tested on PHP 8.2; it's default is PHP 7.4.

joseph.olstad’s picture

webform_localization automation tests for PHP 8.2.x led me to create this:
#3333988: PHP 8.2 compatibility fix

It's a harmless change, I think it'll do the trick.

joseph.olstad’s picture

I'm not sure if webform_localization is loading the dev branch of webform as a dependency or the tagged release, it might be choking on the old tagged release.

A new tagged release would likely help also but ya see if you can add this first:

#3333988: PHP 8.2 compatibility fix

liam morland’s picture

Status: Fixed » Closed (works as designed)

Testing uses the latest full release tag. That is probably the problem. If this is still a problem after a new full release is made, please re-open.

I do not think this patch does anything because NULL is the default value.

Please do not RTBC your own patches.

liam morland’s picture

Status: Closed (works as designed) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.