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.
Comment | File | Size | Author |
---|---|---|---|
#13 | 2923286-13.patch | 812 bytes | phenaproxima |
#12 | 2923286-12.patch | 878 bytes | phenaproxima |
| |||
#7 | fatal_error_buildForm_php7.2-2923286-7.patch | 1.92 KB | dimr |
#5 | patched_panels_bug.patch | 2.14 KB | elijahoyekunle |
Comments
Comment #2
cburschkaThis 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).
Comment #3
cburschkaWhoops, 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.
Comment #4
anavarreNow 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
Comment #5
elijahoyekunle CreditAttribution: elijahoyekunle as a volunteer commentedGood day,
I also had the same problem, and I fixed it with this patch.
Please try it out.
Comment #6
amme CreditAttribution: amme commentedComment #7
dimr CreditAttribution: dimr commentedI could not use directly that patch with composer, I have recreated it with git diff and it works for me.
Comment #8
anavarre@dimr - Please don't RTBC your own patch. See https://www.drupal.org/patch/review#review
Comment #9
dimr CreditAttribution: dimr commentedI 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.
Comment #11
phenaproximaI 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.
Comment #12
phenaproximaOkay. 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.
Comment #13
phenaproximaDiscussed 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...
Comment #14
anavarreComment #15
phenaproximaComment #16
phenaproximaComment #17
phenaproximaComment #19
EclipseGc CreditAttribution: EclipseGc commentedFixed and pushed to 8.x-4.x.
Eclipse
Comment #21
rahiarii CreditAttribution: rahiarii commentedHi 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
Comment #22
allenAtSMG CreditAttribution: allenAtSMG commentedIs 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.
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.