php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41205 list() with string assignment not as expected
Submitted: 2007-04-26 16:45 UTC Modified: 2008-07-24 09:08 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: paul at santasoft dot com Assigned: colder (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: centos (linux)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: paul at santasoft dot com
New email:
PHP Version: OS:

 

 [2007-04-26 16:45 UTC] paul at santasoft dot com
Description:
------------
clarification is needed in the documentation in the case of a one-to-one assignment using list() and a string.  see reproduction code example 1.  i understand that in this case, the string is being treated as an array of characters.  But this was not as expected initially.

Plus, a fatal error is generated if the string is directly provided instead of returning from a function.  Inconsistent and confusing.

Reproduce code:
---------------
Example 1:

<?php
function bob_dole_is_a_dork() {
	return 'Bob Dole Smells Like Old Socks!';
}
list($bobdole) = bob_dole_is_a_dork();
echo($bobdole);
?>


Example 2:

<?php
list($bobdole) = 'Bob Dole Smells Like Old Socks!';
echo($bobdole);
?>

Expected result:
----------------
Example 1:

Bob Dole Smells Like Old Socks!



Example 2:

Bob Dole Smells Like Old Socks!


Actual result:
--------------
Example 1 gives:

B

Example 2 gives:

Fatal error: Invalid opcode 98/1/1. in /the/path/doesnt/matter/pp.php on line 2


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-27 02:58 UTC] judas dot iscariote at gmail dot com
<?php
list($bobdole) = 'Bob Dole Smells Like Old Socks!';
echo($bobdole);
?>

atal error: Invalid opcode 98/1/1.was a bug already fixed in CVS. however there $bobdole should be set to NULL and not to "B" as you expect ( or at least that is the bahviuor it has in CVS)

IMHO it should trow a fatal error: "cannot use string as an array"
 [2007-05-01 18:28 UTC] colder@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2008-07-24 09:08 UTC] schmidt@php.net
AFAICT the documentation hasn't been fixed yet (or the error was reintroduced at a later date).

http://www.php.net/list still contains the following example:

// list() doesn't work with strings
list($bar) = "abcde";
var_dump($bar); // NULL

As mentioned, a fatal error is generated, and the var_dump() call is never reached.
 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=0a501a3f617d7d66a9e39668467fd04c8da66387
Log: Fix #41205 (As of PHP 5.2.2 list doesn't work on strings)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 20:01:33 2025 UTC