Skip to content

getAttributeValue() emits null-array-offset deprecation on PHP 8.4+ #19

Closed

Description

@abdul-kaioum

InputDataContainer::getAttributeValue() emits a PHP deprecation on every call made without an explicit $key.

Where

src/InputDataContainer.php (line 37 in the released 1.2.3):

public function getAttributeValue($key = null)
{
    ...
    } elseif (isset($data[$key])) {   // $key is null on the default call

Why it fires

As of PHP 8.4/8.5, isset() is no longer exempt from the null-array-offset deprecation:

$ php -r '$d = ["a" => 1]; $k = null; var_dump(isset($d[$k]));'
PHP Deprecated:  Using null as an array offset is deprecated, use an empty string instead
bool(false)

Verified on PHP 8.5.9. Both isset($data[$key]) and the later $data[$this->attributeKey] read are affected when the value is null.

Impact

Every validated request in a consuming plugin logs the notice. In Bit CRM it also leaks into the HTTP response body — the REST envelope's additional field carries the raw deprecation text, e.g.:

{"status":"success","code":"SUCCESS","data":"Note created successfully!",
 "additional":"\nDeprecated: Using null as an array offset is deprecated, use an empty string instead in .../wp-validator/src/InputDataContainer.php on line 37"}

Suggested fix

Normalize the offset before use, e.g. $key ?? '', or guard with $key !== null && isset($data[$key]). The attributeKey read on the following branch needs the same treatment (it is already null-coalesced at line 31 for trim(), but not where it is used as an offset).

Reproduce

Call any validator rule path that reaches getAttributeValue() with no argument under PHP 8.4+.

Activity

  1. csemazharul commented on Nov 2, 2026

    @csemazharul
    Collaborator

    Fixed by #20, released in 1.2.4. Updating to 1.2.4 or later removes this deprecation from normal Validator runs, including the notice leaking into REST responses. Checked on PHP 8.5.12.

    The deprecation comes from PHP 8.5, not 8.4: PHP 8.4.24 does not emit it.

    Two minor leftovers remain, neither part of the reported problem:

    • same:0 passes on a mismatch, because $key && treats 0 and '0' as no key. This only affects a same rule pointing at a field named 0.
    • InputDataContainer still emits the deprecation when it is used directly with no attribute key set. Validator always sets a key, so it does not hit this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions