Doc #77323 [Opn]: Since 7.1 $var[] = 'entry'; throws Fatal. This is unclear in the docs.
Edit report at https://bugs.php.net/bug.php?id=77323&edit=1
ID: 77323
Updated by: girgias@php.net
Reported by: powtac at gmx dot de
Summary: Since 7.1 $var[] = 'entry'; throws Fatal. This is
unclear in the docs.
Status: Open
Type: Documentation Problem
-Package: Documentation problem
+Package: Arrays related
-Operating System: linux
+Operating System: N/A
-PHP Version: 7.1.25
+PHP Version: >= 7.1
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2018-12-20 10:43:50] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77323&edit=1
Thread (4 messages)