php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40590 list($k,$v) = $v; gives unexpected output
Submitted: 2007-02-22 13:26 UTC Modified: 2007-02-24 16:11 UTC
From: black at scene-si dot org Assigned: sean (profile)
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.1 OS: linux
Private report: No CVE-ID: None
 [2007-02-22 13:26 UTC] black at scene-si dot org
Description:
------------
list() overwriting variable, unexpected result (different from php4).

Reproduce code:
---------------
$v = array("00","-- Day --");
list($k,$v) = $v;
var_dump(array($k,$v));

Expected result:
----------------
Var dump should return:

array(2) {
  [0]=>  string(2) "00"
  [1]=>  string(11) "-- Day -- "
}

Actual result:
--------------
Var dump returns:

array(2) {
  [0]=>  string(1) "-"
  [1]=>  string(11) "-- Day -- "
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-24 15:09 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In PHP 5 this is the expected behavior.
 [2007-02-24 15:17 UTC] black at scene-si dot org
Consider fixing the documentation, to reflect this "expected" behaviour. I changed the category to documentation problem and status back to open.

Regards,
Tit
 [2007-02-24 16:11 UTC] sean@php.net
This is already documented in function.list:

"list() assigns the values starting with the right-most parameter. If you are using plain variables, you don't have to worry about this. But if you are using arrays with indices you usually expect the order of the indices in the array the same you wrote in the list() from left to right; which it isn't. It's assigned in the reverse order."

$v is being assigned in the first assignment of the list(). When that new $v is used to calculate $k, you're getting the string.

S
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 01:01:23 2020 UTC