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

array_key_exists() error on PHP8+ #5190

Closed
robdekort opened this issue Feb 3, 2022 · 12 comments
Closed

array_key_exists() error on PHP8+ #5190

robdekort opened this issue Feb 3, 2022 · 12 comments
Labels
php php version issues

Comments

@robdekort
Copy link
Contributor

robdekort commented Feb 3, 2022

Bug description

I use a scoped replicators like this:

{{ page_builder scope="block" }}
    {{ partial src="page_builder/{type}" }}
{{ /page_builder }}

The data for one of these replicator sets looks like this"

theme:
  label: secondary
  value:
    - '#395EAB'

The template uses this:

{{ block:theme.label }}

On PHP7.4 this works fine, however on PHP8.1 it results in the following error:

Facade\Ignition\Exceptions\ViewException
array_key_exists(): Argument #2 ($array) must be of type array, Statamic\Fields\Value given

How to reproduce

Happy to share the repo and .env. DM me if needed.

Logs

No response

Versions

Statamic 3.2.32 Pro
Laravel 8.82.0
PHP 8.1.2
rias/statamic-color-swatches 2.0.5

Installation

Starter Kit using via CLI

Additional details

No response

@edalzell
Copy link
Contributor

edalzell commented Feb 3, 2022

Can you please post a bit more of the rot stack trace?

@robdekort
Copy link
Contributor Author

Does this help @edalzell?

The log error was too long for GitHub and sharing the error with Ignition gives an error. Ironically.

Screen Shot 2022-02-03 at 16 01 04

@tao
Copy link
Contributor

tao commented Feb 21, 2022

This bug happens all the time, I get it on my Github deployment pipeline randomly when using a custom tag:

/api/partials/nav/news (array_key_exists(): Argument #2 ($array) must be of type array, Statamic\Fields\Value given)
5050

The custom tag:

    /**
     * The {{ news:latest_year }} tag.
     *
     * @return int
     */
    public function latestYear()
    {
        $collection = $this->params['collection'] ?? 'news';
        $type = $this->params['type'] ?? 'news';

        // fetch the entries in the collection
        $entry = Entry::query()
          ->where('collection', $collection)
          ->where('type', $type)
          ->where('published', true)
          ->orderBy('date', 'desc')
          ->first();

        return $entry->date()->format('Y');
    }

The Github pipeline runs exactly the same time each day but sometimes it works and sometimes it fails with this bug. Maybe it's related...

@jackmcdade jackmcdade added the php php version issues label Mar 2, 2022
@jasonvarga
Copy link
Member

jasonvarga commented Mar 2, 2022

Can you share _sticky_animation.antlers.html Rob?

@robdekort
Copy link
Contributor Author

I think only the first line is relevant:

<section class="relative block-{{ identifier }} {{ block:theme.label or page:theme.label }} bg-theme-main motion-safe:duration-500">

But here's the full thing in case you need it. It's a complex block responsible for the color changing area below the hero on (https://socialebenadering.nl).

<section class="relative block-{{ identifier }} {{ block:theme.label or page:theme.label }} bg-theme-main motion-safe:duration-500">
    {{ partial:snippets/theme selector=".block-{{ identifier }}" :label="theme.label" }}
    <div class="hidden md:block absolute inset-0 py-8 md:py-16 lg:py-24 pointer-events-none">
        <div class="fluid-container sticky top-[25vh] grid md:grid-cols-12 gap-8">
            <figure
                class="md:col-span-6 h-[50vh]"
                x-data="{ animation: '' }"
                x-init="
                    animation = lottie.loadAnimation({
                        container: $el,
                        renderer: 'svg',
                        autoplay: false,
                        loop: false,
                        path: '{{ block:animation }}'
                    }),
                    create({
                        mode: 'scroll',
                        player: animation,
                        container: '.block-{{ identifier }}',
                        actions: [
                            {
                                visibility: [0, .1],
                                type: 'seek',
                                frames: [0, 0],
                            },
                            {
                                visibility: [.1, .9],
                                type: 'seek',
                                frames: [0, {{ block:frames }}],
                            },
                        ],
                    })
                "
                aria-hidden="true"
            >
            </figure>
        </div>
    </div>
    {{ block:blocks }}
        {{ partial:snippets/theme selector=".sub-block-{{ index }}" :label="theme.label" }}
        <div class="sub-block-{{ index }} w-full md:min-h-[60vh] flex flex-col justify-center py-8 md:py-16 lg:py-24 bg-theme-main md:bg-transparent">
            <div class="fluid-container grid md:grid-cols-12 gap-8">
                <div class="md:hidden">
                    <figure
                        x-data="{ animation: '' }"
                        x-init="
                            animation = lottie.loadAnimation({
                                container: $el,
                                renderer: 'svg',
                                autoplay: false,
                                loop: false,
                                path: '{{ animation }}'
                            })
                        "
                        x-intersect="animation.play()"
                        x-intersect:leave="animation.stop()"
                    >
                    </figure>
                </div>
                <article
                    x-data="{ element: document.querySelector('.block-{{ identifier }}') }"
                    x-intersect:enter.half="
                        if ($store.screenSize.desktop) {
                            {{ partial:snippets/theme_intersect }}
                        }
                    "
                    class="relative md:col-start-7 md:col-span-6 self-center">
                    {{ if size == 'sm' }}
                        {{ partial:typography/h2 :content="title" color="text-theme-accent" class="mb-4" }}
                    {{ elseif size == 'lg' }}
                        {{ partial:typography/h1 as="h2" :content="title" color="text-white" class="mb-4" }}
                    {{ /if }}

                    {{ partial:typography/paragraph :content="text" }}

                    {{ partial:components/button }}
                </article>
                {{ partial:components/counter }}
            </div>
        </div>
    {{ /block:blocks }}
</section>

@jasonvarga
Copy link
Member

If you can provide a repo where it's reproducible that'd be cool.

@robdekort
Copy link
Contributor Author

will do!

@robdekort
Copy link
Contributor Author

You should have an invite by now! I'll PM you a .env on Discord.

@jasonvarga
Copy link
Member

Thanks. FYI this happens on 8.0 too.

@robdekort robdekort changed the title array_key_exists() error on PHP8.1 array_key_exists() error on PHP8+ Mar 2, 2022
@jackmcdade jackmcdade removed the antlers label Mar 2, 2022
@jasonvarga
Copy link
Member

Seems to be resolved in the new parser. Could you give it a try?

@robdekort
Copy link
Contributor Author

Will do. It’s a good full fledged website test case for the new parser as well to test all backwards compatibility. @JohnathonKoster beware ;-)!

@robdekort
Copy link
Contributor Author

It's indeed solved with the runtime parser. However some stuff seems broken. I will see if I can fix and document those and if there's a possible bug involved I'll make a new issue.

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

No branches or pull requests

6 participants