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: 2019-01-02 17:02 UTC
Votes:1
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
10 + 17 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Aug 20 23:01:34 2019 UTC