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.
When files are uploaded via ajax and validation happens on the form, PHP 7 will throw a PHP notice on the following code:
elseif ($elements['#type'] == 'select' && !$elements['#multiple'] && $elements['#required'] && !isset($elements['#default_value']) && $elements['#value'] === $elements['#empty_value']) {
To prevent the PHP notice, I've changed it as follows:
elseif ($elements['#type'] == 'select' && $elements['#required'] && (!array_key_exists('#multiple', $elements) || !$elements['#multiple']) && !isset($elements['#default_value']) && $elements['#value'] === $elements['#empty_value']) {
Steps to reproduce:
* run the latest version of Drupal 7 on PHP 7.1
* install file entity module
* add fields to your image type file
* create an article
* upload an image (see the PHP notice after the image is uploaded via ajax)
Comment | File | Size | Author |
---|---|---|---|
core-php-7-notice-form-validate.patch | 986 bytes | jenlampton | |
Comments
Comment #2
jenlamptonSetting status to NR
Comment #3
jenlamptonPatch still cleanly applies to 7.74.
Comment #4
izmeez CreditAttribution: izmeez commentedUpdated issue title for clarity
Comment #5
jenlamptonPatch still cleanly applies to 7.75.
Comment #6
izmeez CreditAttribution: izmeez commentedAdded to #3179845: [meta] Priorities for 2020-12-02 bugfix release of Drupal 7.76 / 7.77, won't get into next release but may help raise it's visibility.
Comment #7
jenlamptonThanks for the update @izmeez! Patch still cleanly applies to 7.78.
Comment #8
izmeez CreditAttribution: izmeez commentedThis issue is included in the new meta issue #3192080: [meta] Priorities for 2021-04-07 release of Drupal 7
Comment #9
jenlamptonPatch still applies to 7.80, 7.81, and 7.82.
Comment #10
mcdruidI wasn't able to reproduce the PHP Notices with file_entity and PHP 7(.4) - quite likely that I wasn't following the steps correctly.
However, the change looks reasonable - if this prevents Notices under some circumstances, that's an improvement.
Comment #12
mcdruidThank you!