|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-05-21 20:10 UTC] nepto at platon dot sk
Description: ------------ Transformation of string variable to array variable does not work as expected when prticular assignment is used. It can be also bug in the var_dump(), but I do not suppose this. Reproduce code: --------------- <?php /* * string-to-array.php * * Developed by Ondrej Jombik <nepto@platon.sk> * Copyright (c) 2004 Platon SDG, http://platon.sk/ * Licensed under terms of GNU General Public License. * All rights reserved. * * Changelog: * 2004-05-10 - created * */ /* $Platon$ */ $str = 'string'; $ar['key'] = $str; var_dump($ar['key']); // string(6) "string" $ar['key']['sub-key'] = $ar['key']; var_dump($ar['key']); /* string(6) "string" but expected is: array(1) { ["sub-key"]=> string(6) "string" } */ $ar['key'] = array('sub-key' => $ar['key']); var_dump($ar['key']); /* now OK: array(1) { ["sub-key"]=> string(6) "string" } */ /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */ ?> Expected result: ---------------- Written in the code. Actual result: -------------- Written in the code as well. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 22:00:01 2025 UTC |
Implicit array creation ONLY occurs if the target variable is either (A) not set, or (B) empty. In this case the target variable is already set to a non-blank string so it qualifies neither of those criteria. It seems to me like this should throw a notice since, as you state, the results are very much unexpected. =================================================================== RCS file: /repository/Zend/Attic/zend_execute.c,v retrieving revision 1.316.2.34 diff -u -r1.316.2.34 zend_execute.c --- Zend/zend_execute.c 1 Apr 2004 22:05:38 -0000 1.316.2.34 +++ Zend/zend_execute.c 21 May 2004 18:59:27 -0000 @@ -780,6 +780,9 @@ array_init(container); break; } + } else if ((container->type == IS_STRING || container->type == IS_BOOL) && + (type == BP_VAR_RW || type == BP_VAR_W)) { + zend_error(E_NOTICE, "Implicit array creation failed: Target variable contains non-empty string or boolean true value."); } switch (container->type) { While this is considered, I'd suggest explicitly initializing your arrays before pushing data onto them.Oh, yes, $ar["key"]["syb-key"] is transformed to $ar["key"][0] ("syb-key" to 0), all is OK, sorry for confusion.