Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grav 1.6.18 is an incomplete fix for PHP 7.4 issues #2750

Closed
gatesphere opened this issue Dec 2, 2019 · 8 comments
Closed

Grav 1.6.18 is an incomplete fix for PHP 7.4 issues #2750

gatesphere opened this issue Dec 2, 2019 · 8 comments
Labels

Comments

@gatesphere
Copy link
Contributor

Hello,

After updating my arch linux server to PHP 7.4 today, Grav 1.6.17 broke. Found a new release of Grav, 1.6.18, which contains the PHP 7.4 fix, and installed it (238ba9b).

Grav is still complaining of an error in Pages.php:

Whoops \ Exception \ ErrorException (E_NOTICE)
Trying to access array offset on value of type null

The indicated code is as follows:

/var/www/<redacted>/public_html/grav/system/src/Grav/Common/Page/Pages.php

                    case 'publish_date':
                        $list[$key] = $child->publishDate();
                        $sort_flags = SORT_REGULAR;
                        break;
                    case 'unpublish_date':
                        $list[$key] = $child->unpublishDate();
                        $sort_flags = SORT_REGULAR;
                        break;
                    case 'slug':
                        $list[$key] = $child->slug();
                        break;
                    case 'basename':
                        $list[$key] = basename($key);
                        break;
                    case 'folder':
                        $list[$key] = $child->folder();
                        break;
                    case (isset($header_query[0]) && is_string($header_query[0])):
                        $child_header = new Header((array)$child->header());
                        $header_value = $child_header->get($header_query[0]);
                        if (is_array($header_value)) {
                            $list[$key] = implode(',',$header_value);
                        } elseif ($header_value) {
                            $list[$key] = $header_value;
                        } else {
                            $list[$key] = $header_default ?: $key;
                        }
                        $sort_flags = $sort_flags ?: SORT_REGULAR;
                        break;
                    case 'manual':
                    case 'default':
                    default:
                        $list[$key] = $key;
                        $sort_flags = $sort_flags ?: SORT_REGULAR;
                }
            }
     
            if (!$sort_flags) {
                $sort_flags = SORT_NATURAL | SORT_FLAG_CASE;
            }

Arguments

    "Trying to access array offset on value of type null"

The highlighted line is 1311 in Pages.php:

$header_value = $child_header->get($header_query[0]);

As you can see, my stacktrace does indeed include the PHP 7.4 fix on 1309, so it appears that 1.6.18 is at best a partial fix.

@rhukster
Copy link
Member

rhukster commented Dec 3, 2019

Ah I guess I didn’t have a test case here I was actually using that filter type. Will require a similar check.

@mahagr
Copy link
Member

mahagr commented Dec 3, 2019

Check Grav 1.7 where I've actually got rid of the array.

@gatesphere
Copy link
Contributor Author

@mahagr Wrong place to ask, I know, but is there a way to get gpm selfupgrade to install 1.7 over my 1.6.18 install?

@rhukster
Copy link
Member

rhukster commented Dec 3, 2019

In your user/config/system.yaml add/change the gpm.releases option as follows:

gpm:
  releases: testing

Then do a force self upgrade:

bin/gpm -f selfupgrade

rhukster added a commit that referenced this issue Dec 3, 2019
@rhukster rhukster closed this as completed Dec 3, 2019
@gatesphere
Copy link
Contributor Author

Please reopen this issue, the fix is still incomplete

Running a version of Grav at commit 41d31cb results in a new error for me, which seems related because it's still referencing Pages.php:

Whoops \ Exception \ ErrorException (E_NOTICE)
Undefined offset: 0

Code highlighted is Line 1313 in Pages.php:

$header_value = $child_header->get($header_query[0]);

Prior to any of this, PHP 7.3/Grav 1.6.17 was working fine.

@rhukster
Copy link
Member

rhukster commented Dec 4, 2019

Clearly PHP 7.4 is much stricter about the case statement.

Can you try replacing the entire 'for' loop with this:

foreach ($pages as $key => $info) {
            $child = $this->instances[$key] ?? null;
            if (!$child) {
                throw new \RuntimeException("Page does not exist: {$key}");
            }

            switch ($order_by) {
                case 'title':
                    $list[$key] = $child->title();
                    break;
                case 'date':
                    $list[$key] = $child->date();
                    $sort_flags = SORT_REGULAR;
                    break;
                case 'modified':
                    $list[$key] = $child->modified();
                    $sort_flags = SORT_REGULAR;
                    break;
                case 'publish_date':
                    $list[$key] = $child->publishDate();
                    $sort_flags = SORT_REGULAR;
                    break;
                case 'unpublish_date':
                    $list[$key] = $child->unpublishDate();
                    $sort_flags = SORT_REGULAR;
                    break;
                case 'slug':
                    $list[$key] = $child->slug();
                    break;
                case 'basename':
                    $list[$key] = basename($key);
                    break;
                case 'folder':
                    $list[$key] = $child->folder();
                    break;
                case 'manual':
                case 'default':
                default:
                    if (isset($header_query[0]) && is_string($header_query[0])) {
                        $child_header = new Header((array)$child->header());
                        $header_value = $child_header->get($header_query[0]);
                        if (is_array($header_value)) {
                            $list[$key] = implode(',', $header_value);
                        } elseif ($header_value) {
                            $list[$key] = $header_value;
                        } else {
                            $list[$key] = $header_default ?: $key;
                        }
                        $sort_flags = $sort_flags ?: SORT_REGULAR;
                    } else {
                        $list[$key] = $key;
                        $sort_flags = $sort_flags ?: SORT_REGULAR;
                    }

            }
        }

@rhukster rhukster added the bug label Dec 4, 2019
rhukster added a commit that referenced this issue Dec 4, 2019
@gatesphere
Copy link
Contributor Author

Sorry I was unable to test the previous comment. However, upgrading to 1.6.19 definitely fixed it on my server. All seems to work fine now. Thanks.

@rhukster
Copy link
Member

rhukster commented Dec 5, 2019

No worries, i actually changed it again to bring it more inline with 1.7 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants