Skip to content

PHP 8.5: array_key_exists() with null key deprecation in HasTabs::modifyQueryWithActiveTab() #19284

@gldrenthe89

Description

@gldrenthe89

Package

filament/filament

Package Version

v5.2.1

Laravel Version

v12

Livewire Version

v4

PHP Version

PHP 8.5.2

Problem description

In src/Resources/Concerns/HasTabs.php on line 75, array_key_exists($this->activeTab, $tabs) is called while $this->activeTab is null. PHP 8.5 deprecates passing null as the key parameter to array_key_exists():

Warning: Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead

This warning fires repeatedly on every table page load, causing noticeable performance degradation due to the volume of warnings generated.

Expected behavior

No deprecation warning should be triggered. The null value of $this->activeTab should be caught before reaching array_key_exists().

Steps to reproduce

  1. Use PHP 8.5
  2. Create any resource with a ListRecords page that has a table
  3. Do not define any tabs (use the default empty getTabs())
  4. Load the list page
  5. Observe repeated deprecation warnings in the log:

Warning: Using null as the key parameter for array_key_exists() is deprecated in vendor/filament/filament/src/Resources/Concerns/HasTabs.php on line 75

The issue is in modifyQueryWithActiveTab(). The guard on line 69 (blank(filled($this->activeTab))) should prevent null from reaching line 75, but it doesn't in all cases. A simple fix:

// Line 75, before:
if (! array_key_exists($this->activeTab, $tabs)) {

// After:
if ($this->activeTab === null || ! array_key_exists($this->activeTab, $tabs)) {

Reproduction repository (issue will be closed if this is not valid)

https://github.com/gldrenthe89/filamentv5-php-deprication-warning

Relevant log output

warning – Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead in /vendor/filament/filament/src/Resources/Concerns/HasTabs.php on line 75

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions