Doc #77323 [Asn->Csd]: Since 7.1 $var[] = 'entry'; throws Fatal. This is unclear in the docs.

From: Date: Mon, 25 Jan 2021 12:38:01 +0000
Subject: Doc #77323 [Asn->Csd]: Since 7.1 $var[] = 'entry'; throws Fatal. This is unclear in the docs.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18441@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77323&edit=1

 ID:                 77323
 Updated by:         cmb@php.net
 Reported by:        powtac at gmx dot de
 Summary:            Since 7.1 $var[] = 'entry'; throws Fatal. This is
                     unclear in the docs.
-Status:             Assigned
+Status:             Closed
 Type:               Documentation Problem
 Package:            Arrays related
 Operating System:   N/A
 PHP Version:        >= 7.1
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2019-01-02 17:02:45] 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.

------------------------------------------------------------------------
[2019-01-01 21:24:26] 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

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

« previous php.doc.bugs (#18441) next »