duck7000 / imdbGraphQLPHP

6 stars 0 forks source link

PHP < 7 #3

Closed GeorgeFive closed 11 months ago

GeorgeFive commented 12 months ago

I use an earlier version of PHP, so technically, this is not compatible with my setup. While I've only done a quick runthrough of the code, SO FAR, I can get around this pretty simply....

title.php, add:

if (! function_exists("array_key_last")) {
    function array_key_last($array) {
        if (!is_array($array) || empty($array)) {
            return NULL;
        }

        return array_keys($array)[count($array)-1];
    }
}

Will dig in more as time allows....

duck7000 commented 12 months ago

Ah i didn't think of that, i use php 8.1 You use a php version smaller then 7 as i understand? That is out of support so that is not wise to use anymore

If this is the only problem i can add this but i'm not sure how i should implant this?

If there are more problems related to old php versions i suggest you try to update your php version.

GeorgeFive commented 12 months ago

You don't have to change any of your code, just tack that quick little function down at the bottom of title.php or something that is called from every script (not at a PC right now so can't look). If a user is using PHP>=7, it will work as normal. If they're using a lesser version, it will use that function (which does the same thing as the official implementation).

Personally, I use an older version because of some legacy code that cannot be easily updated, but is integral to the site functionality.

Anyway, I don't expect you to completely rewrite your code, but most compatibility issues can be fixed with stuff like this.... and at a glance, that's the only issue preventing it from being compatible with older versions.

duck7000 commented 12 months ago

Well every version below php 8 is eol so i don't feel comfortable to add legacy code for unsupported PHP versions.

you can however implant this yourself but i strongly suggest to upgrade and upgrade your legacy code accordingly I have dealt with this problem myself (my program was written in php version 4) so i rewrote the code.

replacing array_key_last with this is a option: $lastKey = key(array_slice($array, -1, 1, true)); but it is slower

Your purposal is not 100% Because this technique will ONLY work on indexed (gapless integer keys starting from zero) arrays. This is almost always the case in title class but to be shure i wont use that

GeorgeFive commented 12 months ago

Fair enough, I totally get where you're coming from. Was throwing this out there for my own personal use, and it may come up later from other users as well....?

duck7000 commented 12 months ago

another user was already complaining that there are methods missing in title class so i can't make everybody happy i guess

I will consider, if that is the only thing from stopping you to use it, to change it to $lastKey = key(array_slice($array, -1, 1, true)); So i suggest to fully test it and report back to me.

GeorgeFive commented 12 months ago

I haven't touched person.php yet, but so far, that's the only compatibility issue I've come across. I'm trying to test as much as I can, as quick as I can.... but with 14+ hour work days this week, I'm strapped for time and only able to do small chunks.

duck7000 commented 12 months ago

take your time, no rush!

duck7000 commented 11 months ago

I.m re open this, maybe other users have the same problem I consider to change it to a older method so php 5.6 or higher is working

GeorgeFive commented 11 months ago

Got another issue with the code changes from #8 :

PHP Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in this line: usort($this->goofs, fn($a, $b) => $a['type'] <=> $b['type'])

I don't use this function, so I can safely strip it out of my release.... just throwing this out there.

duck7000 commented 11 months ago

mm i think this comes from the fact that you use a older php version

I have remove it, the output array is not sorted but the data is still in place

duck7000 commented 11 months ago

I replaced all array_key_last to the other solution we talked about. The performance impact is small so after all no big deal.

The only reason it slightly bothers me is that there is finally a good solution, array_key_last(), but for compatibility reasons not usable here

If this is working right report it back here so we can close this issue successfully :)

EDIT: see #13 this is no longer an issue as i converted them to array (remains the other solution by director, composer, writer and producer for now)

GeorgeFive commented 11 months ago

I am currently using your code "straight out of the box" with no compatibility changes, so looks good!