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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Sun Apr 28 12:01:28 2024 UTC