#23690 [Asn]: Config_Container::toArray() Bug + FIX :-)

From: Date: Mon, 19 May 2003 18:30:38 +0000
Subject: #23690 [Asn]: Config_Container::toArray() Bug + FIX :-)
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16475@lists.php.net to get a copy of this message
ID: 23690 User updated by: info at rhalff dot com Reported By: info at rhalff dot com Status: Assigned Bug Type: PEAR related Operating System: All PHP Version: 4.3.2RC3 Assigned To: mansion New Comment: Ok, so that's kind of excpected behaviour then. To me te fix seems to work, there's only one unlogical thing left in there. if (isset($array[$this->name][$key])) { // duplicate name/type ....... } elseif (isset($array[$this->name][$key][0])) { The elseif will never be reached, since isset($array[$this->name][$key]) will always be true first. Previous Comments: ------------------------------------------------------------------------ [2003-05-19 12:16:29] mansion@php.net Inicommented uses my own parser. Inifile uses the php function parse_ini_file() which is very fast but not as complete. My parser is quite slow but keeps track of comments, blank lines, duplicates... I don't think parse_ini_file() allows duplicate entries. ------------------------------------------------------------------------ [2003-05-19 10:37:44] info at rhalff dot com Ok your right, with the test code I gave for reproduction of this bug the fix works. But if I change the type from 'inicommented' to 'inifile' the array will only contain 1 'extension'. Is this expected behaviour or a bug ? ------------------------------------------------------------------------ [2003-05-19 10:11:22] info at rhalff dot com Ok.. my fix doesn't work either :| ------------------------------------------------------------------------ [2003-05-19 10:01:18] mansion@php.net > Hmm your fix will cause: > [PHP] > extension = bcmath.so > extension = bz2.so > extension = calendar.so > extension = cdpf.so > extension = crack.so > extension = curl.so Array ( [root] => Array ( [PHP] => Array ( [extension] => curl.so ) ) ) No it won't, you should test it. But I will wait to see if you can come up with a better solution before I commit anything. Let me know, Thanks. ------------------------------------------------------------------------ [2003-05-19 09:35:49] info at rhalff dot com Hmm your fix will cause: [PHP] extension = bcmath.so extension = bz2.so extension = calendar.so extension = cdpf.so extension = crack.so extension = curl.so Array ( [root] => Array ( [PHP] => Array ( [extension] => curl.so ) ) ) To me it seems the usage of [0] in the code is wrong. Since it can both mean the first character of a string as the first item in an array. For example try: $string = "Hi there"; echo $string[0]; $string[0] = "other value"; echo $string; I think the code should be something like this: 650: foreach ($newArr as $key => $value) { 651: if (isset($array[$this->name][$key])) { 652: // duplicate name/type if(!is_array($array[$this->name][$key])) { $old = $array[$this->name][$key]; unset($array[$this->name][$key]); $array[$this->name][$key][0] = $old; } $array[$this->name][$key][] = $value; 661: } else { 662: $array[$this->name][$key] = $value; 663: } 664: } I was wrong with the else part in my earlier code fix. Im not very sure my fix is good enough, so I will try to find if there is a better sollution. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/23690 -- Edit this bug report at http://bugs.php.net/?id=23690&edit=1

« previous php.pear.dev (#16475) next »