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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
49 - 44 = ?
Subscribe to this entry?

 
 [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: Thu Apr 25 20:01:45 2024 UTC