Humbly hoping that Drupal 7 will eventually support PHP 7.2, I will be making issues for possible incompatibilities.

create_function() is deprecated in PHP 7.2. Fortunately for us, there is only one create_function() call in whole D7 core.

I will attach a patch for your review. The only call is used as a callback function for one array_map() call. I have moved it to a standard function. This pattern was also followed in the same file.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ayesh created an issue. See original summary.

Ayesh’s picture

Status: Needs review » Needs work

The last submitted patch, 2: drupal_7_php_72_create_function_deprecation-2885129-1.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Ayesh’s picture

Ayesh’s picture

Status: Needs work » Needs review
Ayesh’s picture

Title: create_function() is deprated in PHP 7.2. » [PHP 7.2] create_function() is deprated
MustangGB’s picture

Status: Needs review » Needs work

Why not just use an anonymous function?
e.g.

- $keys = array_map(create_function('$a', 'return (string) (float) $a;'), array_keys($allowed_values));
+ $keys = array_map(function ($a) { return (string) (float) $a; }, array_keys($allowed_values));
Ayesh’s picture

Status: Needs work » Needs review

Thanks for your reply. Yes, that would have been great!
Unfortunately minimum PHP requirement for 7.x is PHP 5.2, but anonymous functions are only available since PHP 5.3.

mithenks’s picture

Title: [PHP 7.2] create_function() is deprated » [PHP 7.2] create_function() is deprecated
apaderno’s picture

Status: Needs review » Reviewed & tested by the community

This is pretty straight.

bkosborne’s picture

Agreed. Also note that this code will never be executed anyway, unless someone is running a version of Drupal 7 from 2010 (that's when the db update hook was written).

oadaeh’s picture

@bkosborne don't assume that won't happen. Not everyone updates their site.

bkosborne’s picture

then they wouldn't need to worry about update hooks anyway ;)

Fabianx’s picture

Issue tags: +Pending Drupal 7 commit

Agree with RTBC, this is pending commit.

Fabianx’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Committed and pushed to 7.x. Thanks all!

  • Fabianx committed 76a4dc7 on 7.x
    Issue #2885129 by Ayesh, bkosborne, kiamlaluno, Fabianx: [PHP 7.2]...

Status: Fixed » Closed (fixed)

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

David_Rothstein’s picture

Agreed. Also note that this code will never be executed anyway, unless someone is running a version of Drupal 7 from 2010 (that's when the db update hook was written).

This should run for anyone updating from Drupal 6 to Drupal 7 also.

In any case, patch looks good!