php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78993 Ellipsis inconsistency
Submitted: 2019-12-19 07:35 UTC Modified: 2019-12-19 14:41 UTC
From: imbolk at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.4.1 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: imbolk at gmail dot com
New email:
PHP Version: OS:

 

 [2019-12-19 07:35 UTC] imbolk at gmail dot com
Description:
------------
It seems to me that there is an inconsistency in the PHP syntax associated with T_ELLIPSIS.

Test script:
---------------
$a = [[1,2,3], [4,5,6]];
var_dump(...($a));
var_dump(...(...($a)));

Expected result:
----------------
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
array(3) {
  [0]=>
  int(4)
  [1]=>
  int(5)
  [2]=>
  int(6)
}

array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}

Actual result:
--------------
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
array(3) {
  [0]=>
  int(4)
  [1]=>
  int(5)
  [2]=>
  int(6)
}

PHP Parse error:  syntax error, unexpected '...' (T_ELLIPSIS) in Command line code on lineā€¦

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-19 08:01 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-12-19 08:01 UTC] requinix@php.net
T_ELLIPSIS can only be used in an array or as a function argument. It unpacks an expression, and it is not an expression itself.
 [2019-12-19 08:54 UTC] imbolk at gmail dot com
What about var_dump(...($a));?

($a) is not expression?
 [2019-12-19 08:58 UTC] d8150650 at urhen dot com
BTW var_dump(...[[1],2,3][0]); works fine.
 [2019-12-19 14:13 UTC] imbolk at gmail dot com
Oh yes! What about something like this:

const ONE=1;
var_dump(...array_map(null, [1,2],[3,4])[ONE/ONE-1]);

It's works! Isn't that an expression?
 [2019-12-19 14:41 UTC] nikic@php.net
Of course you can use anything to the right of "...". The point is that "...expr" in itself is not an expression. What is "$a = ...$b" supposed to mean, for example? Only the call(...expr) and [...expr] have any well-defined meaning, and only they are supported.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 08:01:28 2024 UTC