Skip to content

php 8.5: fix deprecation of null as array key - #227

Merged
falkenhawk merged 4 commits into
php85-compatfrom
php85-null-array-offset
Apr 7, 2026
Merged

falkenhawk merged 4 commits into
php85-compatfrom
php85-null-array-offset

Conversation

@falkenhawk

@falkenhawk falkenhawk commented Apr 3, 2026 •

Copy link
Copy Markdown
Member

Note

Using null as an array key (e.g. $array[$nullValue]) was a widely common pattern in older PHP codebases, so this initially looked like a possible breaking change for downstream projects.
However, PHP has always silently cast null to "" (empty string) in this context - $array[null] and $array[""] are fully equivalent - so replacing one with the other is a no-op behavior change. If your project has the same pattern, the fix is straightforward: $var ?? '' wherever a nullable variable is used as array offset.

PHP 8.5 deprecates using null as an array offset and as the key parameter for array_key_exists(). This was a widely used pattern in ZF1 where null gets passed as array key through various code paths.

approach

Since $array[null] was always equivalent to $array[''], the fix is to make the implicit cast explicit using null coalescing ($var ?? '') at the point where the variable is used as array offset. This preserves backward compatibility exactly.

changes by package

package file fix
zend-form Form.php $arrayPath ?? '' in _dissolveArrayValue() and _attachToArray()
zend-db Db/Select.php $correlationName ?? '' in array_key_exists() call in columns()
zend-rest Rest/Server.php $this->_method ?? '' in fault()
zend-timesync TimeSync.php $alias ?? '' in _addServer()
zend-http Http/Client.php $name ?? '' in _setParameter()
zend-navigation Navigation/Container.php $hash ?? '' in current() and getChildren()
zend-translate Translate/Adapter/Tmx.php $this->_tuv ?? '' and $this->_tu ?? '' in _endElement()
zend-file-transfer File/Transfer/Adapter/Http.php $files ?? '' for array key in isValid()
zend-filter Filter/Input.php array_shift($keys) ?? '' in NotEmpty validator check
zend-test Test/PHPUnit/Db/DataSet/DbTableDataSet.php $table->info('name') ?? '' in addTable()

followup to #225

@falkenhawk
falkenhawk marked this pull request as draft April 3, 2026 14:22
@falkenhawk falkenhawk changed the title fix php 8.5 deprecation of null as array key php 8.5: fix deprecation of null as array key Apr 3, 2026
@falkenhawk
falkenhawk force-pushed the php85-null-array-offset branch 3 times, most recently from cb7ff09 to 5815fe8 Compare April 3, 2026 19:16
@falkenhawk
falkenhawk force-pushed the php85-null-array-offset branch from 5815fe8 to 5f51b6d Compare April 3, 2026 19:19
@falkenhawk
falkenhawk marked this pull request as ready for review April 7, 2026 16:34
@falkenhawk
falkenhawk merged commit fbd6c30 into php85-compat Apr 7, 2026
10 checks passed
@falkenhawk
falkenhawk deleted the php85-null-array-offset branch April 7, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant