Doc #71030 [Opn->Ver]: PHP 7.0 list() behavior

From: Date: Sat, 05 Dec 2015 01:36:30 +0000
Subject: Doc #71030 [Opn->Ver]: PHP 7.0 list() behavior
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12903@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71030&edit=1

 ID:                 71030
 Updated by:         requinix@php.net
 Reported by:        filippo dot desantis at gmail dot com
 Summary:            PHP 7.0 list() behavior
-Status:             Open
+Status:             Verified
 Type:               Documentation Problem
 Package:            *General Issues
 Operating System:   OSX
 PHP Version:        7.0.0
 Block user comment: N
 Private report:     N

 New Comment:

https://3v4l.org/vBGTH

It looks like the RHS variable does not get reevaluated. This is the behavior that would make the
most sense to me, but it does contradict what the AST RFC says. I haven't found any talk about
changing how list() works post-RFC.

So either
a) list() is not behaving correctly, or
b) The warning can be removed and the migration guide needs to mention the change


Previous Comments:
------------------------------------------------------------------------
[2015-12-04 16:41:23] filippo dot desantis at gmail dot com

Description:
------------
I'm using

PHP 7.0.0 (cli) (built: Dec  2 2015 13:35:31)
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

Running the example in the RFC https://wiki.php.net/rfc/abstract_syntax_tree
for the list() function 

$a = [1, 2];
list($a, $b) = $a;
 
// OLD: $a = 1, $b = 2
// NEW: $a = 1, $b = null + "Undefined index 1"


I don't get the "NEW" result but the "OLD" one.

Looking for some more information I found in the documentation (http://php.net/list) the warning
"Modification of the array during list() execution (e.g. using list($a, $b) = $b) results in
undefined behavior.".

I was wondering which of the two behaviour should be the good one :)






Test script:
---------------
<?php

$a = [1, 2];
list($a, $b) = $a;

var_dump($a, $b);



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71030&edit=1


Thread (2 messages)

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