php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27564 list behavior
Submitted: 2004-03-11 04:49 UTC Modified: 2004-03-11 05:24 UTC
From: bolk at hitv dot ru Assigned:
Status: Wont fix Package: Documentation problem
PHP Version: 4.3.4 OS: Windows ME
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bolk at hitv dot ru
New email:
PHP Version: OS:

 

 [2004-03-11 04:49 UTC] bolk at hitv dot ru
Description:
------------
This is correct but no record in documentation:

$test = 'Test';
list ($a, $b) = $test;
echo $a.$b;

Reproduce code:
---------------
$test = 'Test';
list ($a, $b) = $test;
echo $a.$b;

Expected result:
----------------
it prints: Te


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-11 05:15 UTC] derick@php.net
It's a side affect, I don't think we should document this :-) (Also, don't rely on this behavior)
 [2004-03-11 05:24 UTC] bolk at hitv dot ru
Funny side effect :)) By the way this behavior may cause some problem:

function Test()
{
  $res = some_user_func();
  return count($res) == 1 ? $res[0] : $res;
}
list ($a) = Test();

If some_user_func returns "array(1,2)" then $a will contains '1' but if it returns array('Test') then $a will contains 'T'.

I think it will be better if PHP cause notice or something in this way or make right type conversion.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC