#41205 [Csd]: list() with string assignment not as expected
| From: | schmidt@php.net | Date: | Thu, 24 Jul 2008 09:08:44 +0000 |
| Subject: | #41205 [Csd]: list() with string assignment not as expected | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-998@lists.php.net to get a copy of this message | ||
ID: 41205
Updated by: schmidt@php.net
Reported By: paul at santasoft dot com
Status: Closed
Bug Type: Documentation problem
Operating System: centos (linux)
PHP Version: Irrelevant
Assigned To: colder
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2007-05-01 18:28:12] 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.
------------------------------------------------------------------------
[2007-04-27 02:58:41] 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-04-26 16:45:49] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41205&edit=1