Problem/Motivation

If you try to install HEAD of Panels on a server running PHP 7.2, it craps out with a fatal error:

PHP Fatal error: Declaration of Drupal\panels\Form\PanelsAddBlockForm::buildForm(array $form, Drupal\Core\Form\FormStateInterface $form_state, ?Symfony\Component\HttpFoundation\Request $request = NULL, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) must be compatible with Drupal\panels\Form\PanelsBlockConfigureFormBase::buildForm(array $form, Drupal\Core\Form\FormStateInterface $form_state, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) in panels/src/Form/PanelsAddBlockForm.php on line 14

This is an unexpected effect caused by a a change to parameter handling introduced in PHP 7.2.

Proposed resolution

Simply pass $request in as the final, optional parameter to buildForm(), rather than stuff it as a new optional parameter in the middle of the buildForm() method signature.

Remaining tasks

Get the latest patch committed.

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stmh created an issue. See original summary.

cburschka’s picture

Status: Active » Closed (duplicate)

This seems to match the one filed here: #2927173: Fatal error on PHP 7.2: Method signature compatibility strictly enforced (newer, but it has more info).

cburschka’s picture

Status: Closed (duplicate) » Active

Whoops, missed the fact that this isn't a core issue. :P

Still the same problem, though. I suspect there will be lots of similar bugs popping up in contrib shortly.

anavarre’s picture

Title: Fatal error on PHP 7.2 » Fatal error in Drupal\panels\Form\PanelsAddBlockForm::buildForm() with PHP 7.2
Priority: Normal » Major
Issue tags: -php-7.2 +PHP 7.2

Now that PHP 7.2 is out, this should be considered major.

Here's the backtrace when installing Lightning, which uses Panels 8.x-4.2:

[Tue Dec 12 10:49:53.989112 2017] [proxy_fcgi:error] [pid 25894:tid 139899049617152] [client 203.0.113.2:54804] AH01071: Got error 'PHP message: PHP Fatal error: Declaration of Drupal\\panels\\Form\\PanelsAddBlockForm::buildForm(array $form, Drupal\\Core\\Form\\FormStateInterface $form_state, ?Symfony\\Component\\HttpFoundation\\Request $request = NULL, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) must be compatible with Drupal\\panels\\Form\\PanelsBlockConfigureFormBase::buildForm(array $form, Drupal\\Core\\Form\\FormStateInterface $form_state, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) in /var/www/html/lightning/docroot/modules/contrib/panels/src/Form/PanelsAddBlockForm.php on line 14\nPHP message: PHP Stack trace:\nPHP message: PHP 1. {main}() /var/www/html/lightning/docroot/core/install.php:0\nPHP message: PHP 2. install_drupal() /var/www/html/lightning/docroot/core/install.php:44\nPHP message: PHP 3. install_run_tasks() /var/www/html/lightning/docroot/core/includes/install.core.inc:117\nPHP message: PHP 4. install_run_task() /var/www/html/lightning/docroot/core/includes/install.core.inc:555\nPHP message: PHP 5. _batch_page() /var/www/html/lightning/docroot/core/includes/install.core.inc:647\nPHP message: PHP 6. _batch_do() /var/www/html/lightning/docroot/core/includes/batch.inc:93\nPHP message: PHP 7. _batch_process() /var/www/html/lightning/docroot/core/includes/batch.inc:137\nPHP message: PHP 8. _install_module_batch() /var/www/html/lightning/docroot/core/includes/batch.inc:294\nPHP message: PHP 9. Drupal\\Core\\ProxyClass\\Extension\\ModuleInstaller->install() /var/www/html/lightning/docroot/core/includes/install.core.inc:1813\nPHP message: PHP 10. Drupal\\Core\\Extension\\ModuleInstaller->install() /var/www/html/lightning/docroot/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php:83\nPHP message: PHP 11. Drupal\\Core\\ProxyClass\\Routing\\RouteBuilder->rebuild() /var/www/html/lightning/docroot/core/lib/Drupal/Core/Extension/ModuleInstaller.php:313\nPHP message: PHP 12. Drupal\\Core\\Routing\\RouteBuilder->rebuild() /var/www/html/lightning/docroot/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php:83\nPHP message: PHP 13. Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher->dispatch() /var/www/html/lightning/docroot/core/lib/Drupal/Core/Routing/RouteBuilder.php:184\nPHP message: PHP 14. Drupal\\Core\\EventSubscriber\\EntityRouteAlterSubscriber->onRoutingRouteAlterSetType() /var/www/html/lightning/docroot/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:108\nPHP message: PHP 15. Drupal\\Core\\Entity\\EntityResolverManager->setRouteOptions() /var/www/html/lightning/docroot/core/lib/Drupal/Core/EventSubscriber/EntityRouteAlterSubscriber.php:48\nPHP message: PHP 16. Drupal\\Core\\Entity\\EntityResolverManager->getControllerClass() /var/www/html/lightning/docroot/core/lib/Drupal/Core/Entity/EntityResolverManager.php:206\nPHP message: PHP 17. class_exists() /var/www/html/lightning/docroot/core/lib/Drupal/Core/Entity/EntityResolverManager.php:72\nPHP message: PHP 18. spl_autoload_call() /var/www/html/lightning/docroot/core/lib/Drupal/Core/Entity/EntityResolverManager.php:72\nPHP message: PHP 19. Symfony\\Component\\ClassLoader\\ApcClassLoader->loadClass() /var/www/html/lightning/docroot/core/lib/Drupal/Core/Entity/EntityResolverManager.php:72\nPHP message: PHP 20. require() /var/www/html/lightning/vendor/symfony/class-loader/ApcClassLoader.php:110\n', referer: http://lightning.local/core/install.php?profile=lightning&langcode=en&continue=1&id=1&op=start

elijahoyekunle’s picture

Good day,
I also had the same problem, and I fixed it with this patch.
Please try it out.

amme’s picture

Status: Active » Needs review
dimr’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.92 KB

I could not use directly that patch with composer, I have recreated it with git diff and it works for me.

anavarre’s picture

Status: Reviewed & tested by the community » Needs review

@dimr - Please don't RTBC your own patch. See https://www.drupal.org/patch/review#review

dimr’s picture

I understand your point of view @anavarre, I was not sure about that part, I did it because it is not my patch, is the patch of @elijahoyekunle I only changed the format.

The last submitted patch, 5: patched_panels_bug.patch, failed testing. View results

phenaproxima’s picture

Status: Needs review » Needs work

I was able to confirm @anavarre's error on my localhost as well, running PHP 7.2.1. And I was able to confirm that the patch in #7 avoids the fatal error.

However, looking at the patch, I don't understand two things:

1) What in this patch is PHP 7.2-specific, exactly? The issue summary is talking about a completely different error.
2) The request parameter does not appear to get used at all. So how the hell does this patch work? How does it fix the error?

I need to understand this stuff before I'd be comfortable either RTBCing this patch, or bringing it into Lightning. I'll investigate a little.

phenaproxima’s picture

Priority: Major » Critical
Status: Needs work » Needs review
FileSize
878 bytes

Okay. I have looked into this further, and I have some answers:

I confirmed that this bug happens on PHP 7.2, but not PHP 7.1. After examining the PHP documentation, I believe that this is an unexpected effect caused by a a change to parameter handling introduced in PHP 7.2.

The optimal solution is not to stuff a new request parameter into the parent::buildForm() method signature. Instead, the method should use $this->getRequest().

That's what the patch does. I have tested it and confirmed that it fixes the problem on PHP 7.2, and I will add it to Lightning shortly. I'm also upgrading this issue to critical, since it completely breaks Panels on PHP 7.2.

phenaproxima’s picture

Discussed with @EclipseGc on Slack and we decided that it would be preferable to simply pass $request in as the final, optional parameter to buildForm(), rather than call getRequest(). I tested this on PHP 7.2 and it worked for me, so here we go...

anavarre’s picture

Issue summary: View changes
phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

Issue summary: View changes

EclipseGc’s picture

Status: Needs review » Fixed

Fixed and pushed to 8.x-4.x.

Eclipse

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rahiarii’s picture

Version: 8.x-4.x-dev » 8.x-4.2

Hi all !

Is this issue fixed ?

I get the same error message on 8.4.2 version.

buildForm signature seems to not changed.

public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) {

No error when running on PHP 7.1

Thanks for help

allenAtSMG’s picture

Is this issue resolved? I recently upgraded my acsf sites locally to Drup 8.5.1 / BLT 9.4 / Drush 9.2.4.

When I upgraded my dependencies from php7.1 to php7.2, and ran a 'blt setup --site=[site]' I ran into this error.

Fatal error: Declaration of Drupal\panels\Form\PanelsAddBlockForm::buildForm(array $form, Drupal\Core\Form\FormStateInterface $form_state, ?Symfony\Component\HttpFoundation\Request $request = NULL, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) must be compatible with Drupal\panels\Form\PanelsBlockConfigureFormBase::buildForm(array $form, Drupal\Core\Form\FormStateInterface $form_state, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) in /var/www/scotts/docroot/modules/contrib/panels/src/Form/PanelsAddBlockForm.php on line 14

I see patches for 8.4.x, but nothing for core 8.5.1. I am just going to try the approved patch, to see what happens, but I thought I'd ask the community for their thoughts.