php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74064 [ZH] 这个也能错???
Submitted: 2017-02-09 01:27 UTC Modified: 2017-02-26 04:22 UTC
From: bhg at live dot it Assigned:
Status: No Feedback Package: Translation problem
PHP Version: 7.1.1 OS: Windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-02-09 01:27 UTC] bhg at live dot it
Description:
------------
---
From manual page: http://php.net/manual/zh/migration71.new-features.php
---


Test script:
---------------
$data = [
    ['id' => 1, 'name' => 'Tom'],
    ['id' => 2, 'name' => 'Fred'],
];

while (['id' => $id, 'name' => $name] = $data) {
    echo $id, $name;
    // logic here with $id and $name
}

Expected result:
----------------
$data = [
    ["id" => 1, "name" => 'Tom'],
    ["id" => 2, "name" => 'Fred'],
];

// list() style
list("id" => $id1, "name" => $name1) = $data[0];

// [] style
["id" => $id1, "name" => $name1] = $data[0];

// list() style
foreach ($data as list("id" => $id, "name" => $name)) {
    // logic here with $id and $name
}

// [] style
foreach ($data as ["id" => $id, "name" => $name]) {
    // logic here with $id and $name
}

Actual result:
--------------
$data = [
    ['id' => 1, 'name' => 'Tom'],
    ['id' => 2, 'name' => 'Fred'],
];

while (['id' => $id, 'name' => $name] = $data) {
    echo $id, $name;
    // logic here with $id and $name
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-09 16:47 UTC] cmb@php.net
-Summary: 这个也能错??? +Summary: [ZH] 这个也能错???
 [2017-02-13 06:13 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2017-02-13 06:13 UTC] laruence@php.net
你想说哪里错了? 
what the problem here?

thanks
 [2017-02-26 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC