php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77323 Since 7.1 $var[] = 'entry'; throws Fatal. This is unclear in the docs.
Submitted: 2018-12-20 10:43 UTC Modified: 2021-01-25 12:33 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: powtac at gmx dot de Assigned: cmb (profile)
Status: Closed Package: Arrays related
PHP Version: >= 7.1 OS: N/A
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: powtac at gmx dot de
New email:
PHP Version: OS:

 

 [2018-12-20 10:43 UTC] powtac at gmx dot de
Description:
------------
---
From manual page: https://php.net/function.array-push
---

Despite the note in the documentation "Note: array_push() will raise a warning if the first argument is not an array. This differs from the $var[] behaviour where a new array is created.",  this is not correct for PHP >= 7.1 where a Fatal Error is thrown when the variable is a empty string.

See https://3v4l.org/SPBA6

Test script:
---------------
$var = '';
$var[] = 'make me an array';

Expected result:
----------------
According to the docs a new array should be created. 

Actual result:
--------------
Fatal error: Uncaught Error: [] operator not supported for strings in /in/SPBA6:5 Stack trace: #0 {main} thrown in /in/SPBA6 on line 5
Process exited with code 255.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-01 21:24 UTC] girgias@php.net
-Package: Documentation problem +Package: Arrays related -Operating System: linux +Operating System: N/A -PHP Version: 7.1.25 +PHP Version: >= 7.1
 [2019-01-01 21:24 UTC] girgias@php.net
This change is documented in the migration guide: https://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.array-order

Moreover, this change applies to all array functions and not just array_push() and I don't think that this old behavior should be documented (due to the fact everything pre PHP 7.1 is EOL).

Regards
 [2019-01-02 17:02 UTC] cmb@php.net
> […] and I don't think that this old behavior should be
> documented (due to the fact everything pre PHP 7.1 is EOL).

The PHP manual is currently supposed to document the behavior for
all PHP versions as of PHP 5.0.0.
 [2021-01-25 12:33 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-01-25 12:38 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=627fb8f8675566dfd9c3977e3ad2d9fc7b3b3876
Log: Fix #77323: Since 7.1 $var[] = 'entry'; throws Fatal. This is unclear in the docs.
 [2021-01-25 12:38 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2021-01-25 15:46 UTC] mumumu@php.net
Automatic comment on behalf of mumumu@mumumu.org
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=739249c56c09881ff7e16c3be78a24700a23b2e4
Log: Fix #77323: Since 7.1 $var[] = 'entry'; throws Fatal. This is unclear in the docs.
 [2021-02-08 08:33 UTC] avenger@php.net
Automatic comment on behalf of avenger
Revision: http://git.php.net/?p=doc/zh.git;a=commit;h=674d0a411c8bcc3031189da5aec292adbf059f76
Log: sync to en: Fix #77323
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 05:01:37 2025 UTC