I would like to use array_column() in some of my 7.x modules, but the function was added in PHP 5.5. There is a single-file PHP library that can be dropped in, with appropriate license wrangling, to provide equivalent functionality in older versions of PHP.

Other modules have started adding this library, in particular WinCache Drupal in #2551849: FR: Add support for PHP versions prior to 5.5 or boost module requirements.

Rather than see modules require PHP 5.5 for one function or (worse) include multiple copies of the array_column library, I'd like to see Drupal core include it in the PHP compatibility layer.

Comments

John Franklin created an issue. See original summary.

cilefen’s picture

Issue tags: +PHP 5.5
john franklin’s picture

Issue summary: View changes
cilefen’s picture

This isn't related directly, but it is an issue where we are trying to bring in a library #2343043: valid_email_address() should use egulias/EmailValidator and become deprecated.

cilefen’s picture

I don't know of a issue a quite like this so I don't know how likely it is to be considered for D7 core.. A suggestion:

  • Create a utility module that uses the libraries API to load the function.
  • Site admins download the backport library to sites/all/libraries.

Or, distribute the library with the utility module if the license is compatible. That would be easier.

cilefen’s picture

#2551849: FR: Add support for PHP versions prior to 5.5 or boost module requirements has switched to requiring PHP 5.5.

Rather than see modules require PHP 5.5 for one function or (worse) include multiple copies of the array_column library, I'd like to see Drupal core include it in the PHP compatibility layer.

PHP 5.4 is on its last ever release. Why support it?

john franklin’s picture

Lots of places are running very old versions of PHP. Even though PHP 5.4 reaches end of security support very soon, that doesn't mean every web hosting site will magically upgrade to 5.5.

Perhaps Drupal 7 should require PHP >=5.5?

cilefen’s picture

Regarding what I wrote in #5:

I don't know of a issue a quite like this so I don't know how likely it is to be considered for D7 core.

What I really mean by that is that I, as in I myself, don't know of other instances of shipping whole libraries with Drupal 7. 8, yes, but not 7. But I could be wrong about this.

cilefen’s picture

Tagging "Needs release manager review" so we could maybe get some feedback before proceeding.

john franklin’s picture

While it bills itself as a library, that's a pretty strong term for it. It's one function, maybe 100 lines long, wrapped in an "if (!function_exists())" check.

cilefen’s picture

Issue tags: +licensingpolicy

It is technically possible we can copy it and credit it but I don't know how that works in terms of licensing.

cilefen’s picture

I guess make a patch. I think it would go in common.inc or something.

David_Rothstein’s picture

I'm not really sure how the licensing policy works. I thought it had to be GPL (not just GPL-compatible) for the code to live on drupal.org, but on the other hand we already have modules/system/system.tar.inc in core, which appears to be non-GPL...

I wonder if it has to be in its own file (to make the licensing more clear?), but again not sure.

Possibly a more standard way to do it would be to define drupal_array_column() in common.inc, which calls the standard PHP array_column() function if it's available, and otherwise loads this extra library and uses that? That way the code only gets loaded when necessary. This is sort of what drupal_json_encode() does, for example.

cilefen’s picture

I'm not really sure how the licensing policy works.

We can ask the licensing working group for an opinion.

john franklin’s picture

Status: Active » Needs review
StatusFileSize
new5.67 KB

A candidate patch. I've followed the lead of the system.tar.inc file. This array_column.inc file is the array_column.php file with additional php-doc @tags to cite the source, the Git commit, author, etc. The LICENSE file from the original repository is wrapped in a comment block and pasted to the top of the file. The indentation is then reduced to two spaces to better follow Drupal coding standards.

The file is then included in common.inc along with a number of other inc files.

poker10’s picture

Status: Needs review » Closed (won't fix)

Thanks for opening this and discussion. Considering that the PHP 5.6 EOL date was 31.12.2018, I think this is no longer relevant, as we are not going to introduce new code to support outdated PHP versions in this D7 phase. Therefore I am closing this issue.