|  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: 2019-01-02 17:02 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: powtac at gmx dot de Assigned:
Status: Open Package: Arrays related
PHP Version: >= 7.1 OS: N/A
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: powtac at gmx dot de
New email:
PHP Version: OS:


 [2018-12-20 10:43 UTC] powtac at gmx dot de
From manual page:

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.


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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-01 21:24 UTC]
-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]
This change is documented in the migration guide:

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).

 [2019-01-02 17:02 UTC]
> […] 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.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 22 07:01:25 2020 UTC