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

Fixed: PHP 8: Layout interface broken - Unknown named parameter $id #5312

Closed
indigoxela opened this issue Oct 20, 2021 · 3 comments · Fixed by backdrop/backdrop#3805
Closed

Comments

@indigoxela
Copy link
Member

indigoxela commented Oct 20, 2021

Description of the bug

Part of #5076 (meta).

Layout contexts seem to be broken for entities with PHP 8.

Related failing tests:

---- Layout: Layout Interface Test (LayoutInterfaceTest) ----

Status    Group      Filename          Line    Function                            
---------------------------------------------------------------------------------------
Exception Error      layout.class.inc  801     getContexts()                                                           
    Unknown named parameter $id
Fail      Other      layout.test       824     testContexts()                                                          
    "Node ID: 2" found
...

Steps To Reproduce

  1. Set your site to use PHP 8
  2. Create a layout with path node/% or any other, doesn't seem to matter
  3. Add a context for node ID
  4. ... that's it, you can't

Actual behavior

Error: Unknown named parameter $id in Layout->getContexts() ( ... core/modules/layout/includes/layout.class.inc).

Additional information

I know, what's causing this, but I can't fix it (without breaking something else).

In function getContexts() the settings contain a key-value array, which is passed as argument to the "load function" - node_load (entity_load) in this case, but entity_load doesn't seem to handle this anymore.

What it gets:

array (
  'id' => '2',
)

What it expects:

array(2)

So on PHP 8 entity_load chokes on the "id" key.

Asking @docwilmot for help. 😉

@quicksketch
Copy link
Member

I filed a PR at backdrop/backdrop#3805 that I think will fix this problem.

I think PHP 8 now includes magic parameter mapping, where it will read the name of the parameter and pass in the right value to a function based on the key name. call_user_func_array() used to only use the order of the passed in parameters. Now in PHP 8 it can actually map based on the keys of the parameters. My patch makes PHP 8 behave like previous versions by removing the named keys and using numeric indexes instead.

@indigoxela
Copy link
Member Author

Hehe, array_values() - so simple. (I could have sworn, I tried that - but had other test failures then...)

Tests are passing! And I confirmed locally that adding contexts works properly now on PHP 8. RTBC 👍

@quicksketch
Copy link
Member

Super, I merged backdrop/backdrop#3805 into 1.x and 1.20.x. Thanks @indigoxela!

@jenlampton jenlampton changed the title PHP 8: Layout interface broken - Unknown named parameter $id Fixed: PHP 8: Layout interface broken - Unknown named parameter $id Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants