When PHP version 7.2 is enabled, Rules generates a Fatal Error when the UI is enabled:

( ! ) Fatal error: Declaration of RulesRuleUI::form(&$form, &$form_state, $options = Array) must be compatible with RulesActionContainerUI::form(&$form, &$form_state, $options = Array, $iterator = NULL) in /sites/all/modules/contrib/rules/ui/ui.plugins.inc on line 0

Seems like wrong implementation of OOP, more specifically the Liskov substitution principle

Comments

ReBa created an issue. See original summary.

ReBa’s picture

Version: 7.x-2.10 » 7.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new1.97 KB

In the Dev version, this problem still occurs.
I've created a patch that doesn't generate a fatal error.
Please test & review

Status: Needs review » Needs work
tr’s picture

Category: Bug report » Task
Priority: Critical » Normal
Status: Needs work » Postponed (maintainer needs more info)

Well, first, not critical. Works perfectly on everything but PHP 7.2, and even Drupal core doesn't work on PHP 7.2 yet. Just a normal issue.

Second, not a bug report. Sure, we should support PHP 7.2, but PHP has changed since the Rules code was written so this is not something that was done "wrong" in Rules, it's just that PHP has redefined what "wrong" is in 7.2. PHP 7.2 didn't exist 8 years ago when D7 was written, so this is a "task" to keep up with the most recent version of PHP.

And BTW, that's really funny what you did, quoting OOP theory when talking about PHP. PHP is a joke in the OO world, and while it's gradually improving, things like the above error complains about have been standard in all mainstream OO languages for more than 25 years already. It's not something to be proud about that PHP is finally catching up on imposing some structure.

Third, what you're proposing was already fixed in #2923477: PHP 7.x compatibility issue, and what you're proposing is a revert of that. At least 7 different people tested that patch and found that it solved the Fatal Error on PHP 7.2. While you say "In the Dev version, this problem still occurs", you are wrong - the signature of RulesRuleUI::form() in the -dev version includes the $iterator parameter, so you cannot possibly be seeing the error message in your original post. Perhaps you see a similar message, however you did not post that other message. So while there may still be a similar problem in -dev, you haven't provided enough information for a fix. Regardless, removing the $iterator argument is NOT the correct solution, since $iterator is needed in some of the subclasses like RulesRuleUI.

tr’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
albanaa’s picture

Issue summary: View changes
mdmanouwer’s picture

above patch when i applied to my repository it fixed the issue

thanks

heinz.wegener’s picture

Updating to Rules 7.x-2.11 and Drupal 7.61 should solve the problem.

kwoxer’s picture

Hi heinz.wegener. I have updated Rules and Drupal to that versions, but I still get this error message in frontend as well when using drush commands:

Fatal error: Declaration of RulesConditionalEmptyUI::form(&$form, &$form_state, $options = Array) must be compatible with RulesContainerPluginUI::form(&$form, &$form_state, $options = Array, $iterator = NULL) in /app/src/sites/all/modules/contrib/rules_conditional/includes/rules_conditional.ui.inc on line 0 Call Stack: 0.0003 405240 1. {main}() /app/src/index.php:0 0.0006 408680 2. drupal_bootstrap() /app/src/index.php:20 0.0858 2307024 3. _drupal_bootstrap_full() /app/src/includes/bootstrap.inc:2538 5.3647 39458640 4. module_invoke_all() /app/src/includes/common.inc:5323 5.4670 39724712 5. imageapi_optimize_init() /app/src/includes/module.inc:965 5.4671 39724712 6. _imageapi_optimize_get_methods() /app/src/sites/all/modules/contrib/imageapi_optimize/imageapi_optimize.module:27 5.6733 40324528 7. watchdog() /app/src/sites/all/modules/contrib/imageapi_optimize/imageapi_optimize.module:327 5.6737 40326488 8. module_invoke() /app/src/includes/bootstrap.inc:2012 5.6737 40326864 9. rules_watchdog() /app/src/includes/module.inc:934 5.6737 40326864 10. rules_invoke_event() /app/src/sites/all/modules/contrib/rules/modules/events.inc:180 5.6737 40327240 11. rules_get_cache() /app/src/sites/all/modules/contrib/rules/rules.module:1030 5.6747 40428192 12. RulesEventSet::rebuildEventCache() /app/src/sites/all/modules/contrib/rules/rules.module:395 5.6908 40862936 13. RulesEventSet->__construct() /app/src/sites/all/modules/contrib/rules/includes/rules.plugins.inc:786 5.6908 40862936 14. RulesEventSet->setUp() /app/src/sites/all/modules/contrib/rules/includes/rules.plugins.inc:740 5.6908 40862936 15. rules_get_cache() /app/src/sites/all/modules/contrib/rules/includes/rules.core.inc:339 5.6923 40863016 16. _rules_rebuild_cache() /app/src/sites/all/modules/contrib/rules/rules.module:387 5.7383 42065904 17. RulesConditional->rebuildCache() /app/src/sites/all/modules/contrib/rules/rules.module:428 5.7383 42066656 18. RulesConditional->extendByClass() /app/src/sites/all/modules/contrib/rules/includes/rules.core.inc:382 5.7383 42066656 19. class_implements() /app/src/sites/all/modules/contrib/rules/includes/faces.inc:181 5.7383 42066704 20. spl_autoload_call() /app/src/sites/all/modules/contrib/rules/includes/faces.inc:181 5.7383 42066752 21. drupal_autoload_class() /app/src/sites/all/modules/contrib/rules/includes/faces.inc:181 5.7383 42066752 22. _registry_check_code() /app/src/includes/bootstrap.inc:3408

doostinharrell’s picture

I can also confirm that updating to Drupal 7.61 and Rules 7.x-2.11 when running PHP 7.2 resolves the issue.

beesol’s picture

yes same here core 7.61 and rules 7.x-2.11 on PHP 7.2 resolved

rakesh.gectcr’s picture

Title: Fatal error: Declaration of RulesRuleUI::form ... must be compatible with RulesActionContainerUi::form » Fatal error: Declaration of RulesRuleUI::form ... must be compatible with RulesActionContainerUi::form [Solved]

Yes, Drupal core - 7.64, rules 7.x-2.12 on PHP 7.2 resolved the issue.

izus’s picture

Hello,

confirming these versions work well together
Drupal core - 7.65,
Rules - 7.x-2.12
PHP 7.2.16

Thanks

garrettw’s picture

I'm still getting this error. PHP 7.2, Drupal 7, and Rules are all up to date on my end. It just took down one of my sites so I'll have to fix it and provide a patch shortly.

garrettw’s picture

Scratch that -- the changes I made are the same as the patch at #5 in the related issue. Now what I want to know is how did I manage to not have that code if my Rules module was already at 2.12? So weird.

hunlaprovo’s picture

Fatal error: Declaration of RulesConditionalEmptyUI::form(&$form, &$form_state, $options = Array) must be compatible with RulesContainerPluginUI::form(&$form, &$form_state, $options = Array, $iterator = NULL) in /home/httpd/www/example.hu/html/sites/all/modules/rules_conditional/includes/rules_conditional.ui.inc on line 56
I updated the rules module, but I also have the rules conditional error message. The module has not been updated since 2012. What can be done?

tr’s picture

You need to contact the maintainer of the Rules Conditional module and post your problem in the issue queue for that module, but it looks to me like that problem was already fixed in the -dev release of Rules Conditional by issue #2959426: Incompatibility with PHP 7.2, so first try updating your copy of that module to see if the problem goes away.

sajosh’s picture

I just got this same error when upgrading a Drupal 7 site. I updated to Drupal 7.74, php 7.3 (because 7.4 causes depreciation errors to show up). Rules needed to be updated but I was updating down the list and I got this error.

To solve, I just updated the Rules module to 7.x-2.12, then the error went away. I continued updating other modules.

norman.lol’s picture

StatusFileSize
new1.28 KB

Having a site on PHP 5.6 I'm debugging right now. Rules 7.x-2.10. I can't execute any Drush command because of that error. Sounds critical to me.

$ drush8 cc all

Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Declaration of RulesRuleUI::form(&$form, &$form_state, $options =
Array) must be compatible with RulesActionContainerUI::form(&$form,
&$form_state, $options = Array, $iterator = NULL) in
/Users/leymannx/Sites/mmmgroup/web/sites/all/modules/rules/ui/ui.plugins.inc,
line 80

Fatal error: Declaration of RulesRuleUI::form(&$form, &$form_state, $options = Array) must be compatible with RulesActionContainerUI::form(&$form, &$form_state, $options = Array, $iterator = NULL) in /Users/leymannx/Sites/mmmgroup/web/sites/all/modules/rules/ui/ui.plugins.inc on line 80

Applying the attached patch fixes the issue for me.

tr’s picture

Having a site on PHP 5.6 I'm debugging right now. Rules 7.x-2.10. I can't execute any Drush command because of that error. Sounds critical to me.

@leymannx: This was FIXED in Rules more than THREE years ago - #2923477: PHP 7.x compatibility issue committed on 14 December 2017. The patch committed in that issue is identical to what you posted in #19.

The version of Rules you're using, 7.x-2.10, is almost FOUR years old. Both 7.x-2.11 and 7.x-2.12 include this fix. 7.x-2.10 is obsolete, can't be changed, and is no longer supported. Keep your modules and your version of core up-to-date and you won't have problems like this.

norman.lol’s picture

THANK YOU for telling me.

aswathyajish’s picture

Thanks. Patch in #19 worked for me.

yaach’s picture

Same issue with PHP 7.4, Rules 7.x-2.10. Updated to 7.x-2.11 and error went away.