Problem/Motivation

fail: [PHP Deprecated] Line 58 of sites/all/modules/ctools/plugins/contexts/entity.inc:
 Optional parameter $data declared before required parameter $plugin is implicitly treated as a required parameter

exception: [Deprecated] Line 535 of sites/all/modules/ctools/includes/math-expr.inc:
preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated

TypeError: Unsupported operand types: string + int in ctools_context_next_id() (line 1125 of /var/www/html/sites/all/modules/ctools/includes/context.inc).

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork ctools-3253226

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review

joelpittet’s picture

Issue summary: View changes

joelpittet’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

liam morland’s picture

With this change, ctools_context_create_entity() can be invoked without a value for the $plugin param. $plugin is then NULL which will raise an error on the first line of the function when it is accessed like an array.

A better fix would be to remove the default value for $conf and $data (as well as $plugin).

An array type declaration should also be added to $plugin. This will cause no harmful side-effects because $plugin must be an array anyway to avoid errors.

beagaliana’s picture

Hi. I know this is marked as fixed and contributions are preferred as a fork+MR. However, I'm having these two errors below and I used part of this issue's solution to fix it, so I thought I might as well share the patch in case is useful to anyone.

I'm using Ctools version 7.x-1.19 with PHP 8.1 and these are the deprecated msgs I'm getting.

Deprecated: Optional parameter $data declared before required parameter $plugin is implicitly treated as a required parameter in /var/www/html/docroot/sites/all/modules/contrib/ctools/plugins/contexts/entity.inc on line 58

Deprecated: Optional parameter $conf declared before required parameter $plugin is implicitly treated as a required parameter in /var/www/html/docroot/sites/all/modules/contrib/ctools/plugins/contexts/entity.inc on line 58

I attach a simple patch based in https://git.drupalcode.org/project/ctools/-/merge_requests/9 to fix it.

liam morland’s picture

A better fix is to remove the defaults. That would fix the errors without causing any side-effects.