MinnPost / object-sync-for-salesforce

WordPress plugin that maps and syncs data between Salesforce objects and WordPress objects.
https://wordpress.org/plugins/object-sync-for-salesforce/
GNU General Public License v2.0
94 stars 51 forks source link

Use of array_key_first breaks compatibility with php < 7.3 #410

Closed nattyg93 closed 3 years ago

nattyg93 commented 3 years ago

Describe the bug https://github.com/MinnPost/object-sync-for-salesforce/blob/c0d101fe5e333c42160f1ac5cc313446f7dd68f3/classes/class-object-sync-sf-salesforce.php#L408

The usage of array_key_first above causes the plugin to be broken with php < 7.3.

To Reproduce Steps to reproduce the behavior:

  1. Install object-sync-for-salesforce 2.0.0
  2. Use php < 7.3 (e.g. 7.0)
  3. Try to access the admin screen
  4. Error due to function not existing

Expected behavior The readme indicates that this plugin is compatible with php 5.6, but does not run with php 7.0

Environment (please complete the following information):

I worked around the issue by adding the following:

if (!function_exists('array_key_first')) {
    function array_key_first(array $arr) {
        foreach($arr as $key => $unused) {
            return $key;
        }
        return NULL;
    }
}
jonathanstegall commented 3 years ago

Thanks. I'm happy to add a fix for this. Some things to note:

  1. Since this code is in a class, I've added a different fix in pull request #411. I wonder if you'd be willing to make sure this works as you'd expect.
  2. I've noticed that adding a global polyfill for this to WordPress has been assigned for version 5.9. Hopefully this will occur and increase the efficiency for users who need that function.
nattyg93 commented 3 years ago

Thanks for the quick turn around on this - I've tested the fix and it solves the issue.