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

From: Date: Wed, 02 Jan 2019 17:02:45 +0000
Subject: Doc #77323 [Opn]: 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-16283@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:             Open
 Type:               Documentation Problem
 Package:            Arrays related
 Operating System:   N/A
 PHP Version:        >= 7.1
 Block user comment: N
 Private report:     N

 New Comment:

> […] 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.


Previous Comments:
------------------------------------------------------------------------
[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 (#16283) next »