<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet href="https://dev.horde.org/themes/horde//default/feed-rss.xsl" type="text/xsl"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
 <channel> 
  <title>ListMessages endless loop</title> 
  <pubDate>Thu, 09 Apr 2026 23:32:30 +0000</pubDate> 
  <link>https://bugs.horde.org/ticket/5604</link> 
  <atom:link rel="self" type="application/rss+xml" title="ListMessages endless loop" href="https://bugs.horde.org/ticket/5604/rss" /> 
  <description>ListMessages endless loop</description> 
 
   
   
  <item> 
   <title>Selecting mail folder results in endless loop of calling Lis</title> 
   <description>Selecting mail folder results in endless loop of calling ListMessages.php. This problem seems to be probably related to specific version of PHP. It doesn&#039;t work on CentOS5 with PHP 5.1.6 (see also http://lists.horde.org/archives/imp/Week-of-Mon-20070716/047606.html) but it works on Fedora 7 with PHP 5.2.2.





There is small difference in data that was returned by ListMessages.php on CentOS5 and Fedora7



CentOS5 (3 mails in INBOX):

/*-secure-{&quot;response&quot;:{ ... ,&quot;msglist&quot;:{}, ... },&quot;msgs&quot;:[],&quot;msgs_auto&quot;:true}*/

Fedora7 (3 mails in INBOX):

/*-secure-{&quot;response&quot;:{ ... ,&quot;msglist&quot;:{&quot;1&quot;:1,&quot;2&quot;:2,&quot;3&quot;:3}, ... },&quot;msgs&quot;:[],&quot;msgs_auto&quot;:true}*/





To get rid of this problem on CentOS, I had to change following piece of code (I did not test it anywhere else, so I&#039;m not sure if this patch works on all PHP versions).





--- dimp-h3-1.0-alpha/lib/Views/ListMessages.php.orig   2007-07-25 07:57:30.000000000 +0200

+++ dimp-h3-1.0-alpha/lib/Views/ListMessages.php        2007-08-06 00:11:50.000000000 +0200

@@ -182,7 +182,7 @@

 

         $result-&gt;lines = count($msglist);

         $result-&gt;msgdata = $msgs;

-        $result-&gt;msglist = (object)$msglist;

+        $result-&gt;msglist = $msglist;

 

         /* Mail-specific viewport information. */

         $md = new stdClass;

</description> 
   <pubDate>Sun, 05 Aug 2007 22:25:59 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35764</link> 
  </item> 
   
  <item> 
   <title>That patch results in the same output for you in msglist, sp</title> 
   <description>That patch results in the same output for you in msglist, specifically that it&#039;s an associative array, not a numerically indexed array?



On the Centos/PHP 5.1.6 box that doesn&#039;t work, do you have a version of the PHP json extension? If you do, then this is likely a bug in that json version, and you should try disabling the json extension that you have (it was mainstreamed in PHP 5.2, so that version should work well).



If that box does *NOT* have a json extension, then this is a bug in Horde_Serialize_JSON and we should add a unit test for it - if this is the case it&#039;d be helpful if you could include a var_export of the $result object so we can toss it into the test quickly.</description> 
   <pubDate>Sun, 05 Aug 2007 23:06:39 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35770</link> 
  </item> 
   
  <item> 
   <title>&gt; If that box does *NOT* have a json extension, then this is</title> 
   <description>&gt; If that box does *NOT* have a json extension, then this is a bug in 

&gt; Horde_Serialize_JSON and we should add a unit test for it - if this 

&gt; is the case it&#039;d be helpful if you could include a var_export of the 

&gt; $result object so we can toss it into the test quickly.



Yes, PHP on CentOS5 doesn&#039;t have json extension. If I use var_export on original code, I get this output:



    &#039;msglist&#039; =&gt; 

  stdClass::__set_state(array(

  )),



but when I remove typecast to &quot;object&quot;, I get different output:



    &#039;msglist&#039; =&gt; 

  array (

    1 =&gt; 1,

    2 =&gt; 2,

    3 =&gt; 3,

  ),

</description> 
   <pubDate>Mon, 06 Aug 2007 00:24:35 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35771</link> 
  </item> 
   
  <item> 
   <title>&gt; Yes, PHP on CentOS5 doesn&#039;t have json extension. If I use </title> 
   <description>&gt; Yes, PHP on CentOS5 doesn&#039;t have json extension. If I use var_export 

&gt; on original code, I get this output:

&gt;

&gt;     &#039;msglist&#039; =&gt;

&gt;   stdClass::__set_state(array(

&gt;   )),

&gt;

&gt; but when I remove typecast to &quot;object&quot;, I get different output:

&gt;

&gt;     &#039;msglist&#039; =&gt;

&gt;   array (

&gt;     1 =&gt; 1,

&gt;     2 =&gt; 2,

&gt;     3 =&gt; 3,

&gt;   ),



That&#039;s weird; that actually indicates to me a PHP bug, that you&#039;re losing the values of the array when casting it to an object.



We need to cast it to an object, otherwise the JSON would probably look like this:



[1, 2, 3]



instead of:



{&#039;1&#039;: 1, &#039;2&#039;: 2, &#039;3&#039;: 3}



(which is important when it&#039;s 10048, 10051, 10046, in that order, and not just 1, 2, 3).



Can you make a short test script which is just:



&lt;?php



var_dump((object)array(&#039;1&#039; =&gt; 1, &#039;2&#039; =&gt; 2));

echo var_export((object)array(&#039;1&#039; =&gt; 1, &#039;2&#039; =&gt; 2), true);





And run it on both versions? (interestingly, the var_export might just mangle it. The var_dump is okay in my case though. Looks like it might be a bug in our json encoder, except that it&#039;s weird that the effect of var_export is exactly what you see when using var_export on it ...)</description> 
   <pubDate>Mon, 06 Aug 2007 02:26:22 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35777</link> 
  </item> 
   
  <item> 
   <title>&gt; Can you make a short test script which is just:

&gt;

&gt; &lt;?ph</title> 
   <description>&gt; Can you make a short test script which is just:

&gt;

&gt; &lt;?php

&gt;

&gt; var_dump((object)array(&#039;1&#039; =&gt; 1, &#039;2&#039; =&gt; 2));

&gt; echo var_export((object)array(&#039;1&#039; =&gt; 1, &#039;2&#039; =&gt; 2), true);

&gt;

&gt;

&gt; And run it on both versions? (interestingly, the var_export might 

&gt; just mangle it. The var_dump is okay in my case though. Looks like it 

&gt; might be a bug in our json encoder, except that it&#039;s weird that the 

&gt; effect of var_export is exactly what you see when using var_export on 

&gt; it ...)



On CentOS5 it returns:

object(stdClass)#1 (2) { [1]=&gt;  int(1) [2]=&gt;  int(2) } stdClass::__set_state(array( ))



On Fedora7 it returns:

&lt;pre&gt;

&lt;b&gt;object&lt;/b&gt;(&lt;i&gt;stdClass&lt;/i&gt;)[&lt;i&gt;1&lt;/i&gt;]

  &lt;small&gt;int&lt;/small&gt; &lt;font color=&#039;#4e9a06&#039;&gt;1&lt;/font&gt;

  &lt;small&gt;int&lt;/small&gt; &lt;font color=&#039;#4e9a06&#039;&gt;2&lt;/font&gt;

&lt;/pre&gt;stdClass::__set_state(array(

))



(btw: PHP on Fedora7 has json extension)

</description> 
   <pubDate>Mon, 06 Aug 2007 02:42:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35781</link> 
  </item> 
   
  <item> 
   <title>It seems that var_export dosn&#039;t work well on objects (it doe</title> 
   <description>It seems that var_export dosn&#039;t work well on objects (it doesn&#039;t print all variables). I use print_r and you can see that typecast to (object) only change data type - the value is still same.





--- horde.log   2007-08-06 08:55:49.000000000 +0200

+++ horde.log.original  2007-08-06 08:56:49.000000000 +0200

@@ -55,7 +55,7 @@

 

         )

 

-    [msglist] =&gt; Array

+    [msglist] =&gt; stdClass Object

         (

             [1] =&gt; 1

             [2] =&gt; 2

</description> 
   <pubDate>Mon, 06 Aug 2007 07:05:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35783</link> 
  </item> 
   
  <item> 
   <title>&lt;?php

$a = array(&#039;1&#039; =&gt; 1, &#039;2&#039; =&gt; 2);

$b = (object)$a;

$c</title> 
   <description>&lt;?php

$a = array(&#039;1&#039; =&gt; 1, &#039;2&#039; =&gt; 2);

$b = (object)$a;

$c = get_object_vars($b);

echo &quot;get_object_vars:\n&quot;;

foreach($c as $name=&gt;$value) {

  echo &quot;  $name: $value\n&quot;;

}

echo &quot;iterator(?):\n&quot;;

foreach($b as $name=&gt;$value) {

  echo &quot;  $name: $value\n&quot;;

}

?&gt;





Output on CentOS5 (PHP 5.1.6):

get_object_vars:

iterator(?):





Output on Fedora7 (PHP 5.2.2):

get_object_vars:

iterator(?):

  1: 1

  2: 2





It means that you can&#039;t use get_object_vars to access array content in lib/Horde/Serialize/JSON.php:161 (on both systems) and with iterator you can access array content only with PHP 5.2.2. If you typecast object back to array, you can access array content also with PHP 5.1.6 (CentOS5).

</description> 
   <pubDate>Mon, 06 Aug 2007 07:47:29 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35784</link> 
  </item> 
   
  <item> 
   <title>&gt; We need to cast it to an object, otherwise the JSON would </title> 
   <description>&gt; We need to cast it to an object, otherwise the JSON would probably 

&gt; look like this:

&gt;

&gt; [1, 2, 3]

&gt;

&gt; instead of:

&gt;

&gt; {&#039;1&#039;: 1, &#039;2&#039;: 2, &#039;3&#039;: 3}



This is precisely the reason.  In javascript land, we are accessing the array via the message index (our message indices just happen to look like integers), which is a string value, rather than an integer value because the latter would indicate the position in the JS array.</description> 
   <pubDate>Tue, 07 Aug 2007 20:06:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35831</link> 
  </item> 
   
  <item> 
   <title>&gt; It means that you can&#039;t use get_object_vars to access arra</title> 
   <description>&gt; It means that you can&#039;t use get_object_vars to access array content 

&gt; in lib/Horde/Serialize/JSON.php:161 (on both systems) and with 

&gt; iterator you can access array content only with PHP 5.2.2. If you 

&gt; typecast object back to array, you can access array content also with 

&gt; PHP 5.1.6 (CentOS5).



To me, this indicates that the version of PHP that ships with CentOS is broken.  If these functions are not doing what they are supposed to be doing, there&#039;s not much we can do about that in our code.  And get_object_vars() has been around since PHP 4 so this shouldn&#039;t be a code stability/maturity issue.

</description> 
   <pubDate>Tue, 07 Aug 2007 20:26:39 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35834</link> 
  </item> 
   
  <item> 
   <title>&gt;&gt; We need to cast it to an object, otherwise the JSON would</title> 
   <description>&gt;&gt; We need to cast it to an object, otherwise the JSON would probably

&gt;&gt; look like this:

&gt;&gt;

&gt;&gt; [1, 2, 3]

&gt;&gt;

&gt;&gt; instead of:

&gt;&gt;

&gt;&gt; {&#039;1&#039;: 1, &#039;2&#039;: 2, &#039;3&#039;: 3}

&gt;

&gt; This is precisely the reason.  In javascript land, we are accessing 

&gt; the array via the message index (our message indices just happen to 

&gt; look like integers), which is a string value, rather than an integer 

&gt; value because the latter would indicate the position in the JS array.



Well, but if you look at your implementation of JSON serialization, you handle asociative arrays differently than normal arrays. See also comment in lib/Horde/Serialize/JSON.php:133



            /* As per JSON spec if any array key is not an integer we

             * must treat the the whole array as an object. We also

             * try to catch a sparsely populated associative array

             * with numeric keys here because some JS engines will

             * create an array with empty indexes up to max_index

             * which can cause memory issues and because the keys,

             * which may be relevant, will be remapped otherwise.

             *

             * As per the ECMA and JSON specification an object may

             * have any string as a property. Unfortunately due to a

             * hole in the ECMA specification if the key is a ECMA

             * reserved word or starts with a digit the parameter is

             * only accessible using ECMAScript&#039;s bracket notation. */



According me it means, that casting associative array with string keys to object is not required (and with cast to object it doesn&#039;t work on probably somehow broken PHP in RHEL5/CentOS5 - I&#039;ll try to figure out the reason why get_object_vars doesn&#039;t work on this system, but right now I tested PHP 5.1.6 compiled from sources and it doesn&#039;t work either).</description> 
   <pubDate>Wed, 08 Aug 2007 03:13:47 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35838</link> 
  </item> 
   
  <item> 
   <title>&gt; To me, this indicates that the version of PHP that ships w</title> 
   <description>&gt; To me, this indicates that the version of PHP that ships with CentOS 

&gt; is broken.  If these functions are not doing what they are supposed 

&gt; to be doing, there&#039;s not much we can do about that in our code.  And 

&gt; get_object_vars() has been around since PHP 4 so this shouldn&#039;t be a 

&gt; code stability/maturity issue.



Well I made tests with script I send ealier with other four different versions of PHP and the result for 5.x versions are always same (bad), version 4.x works:





Official windows version PHP 4.4.7 - get_object_vars works:



c:\Documents and Settings\vokac\Desktop\php-4.4.7-Win32&gt;php test.php

X-Powered-By: PHP/4.4.7

Content-type: text/html



get_object_vars:

  &gt;&gt; 1: 1

  &gt;&gt; 2: 2

iterator(?):

  &gt;&gt; 1: 1

  &gt;&gt; 2: 2







Official windows version PHP 5.2.3 - get_object_vars doesnt work:



c:\Documents and Settings\vokac.ATLASDELL\Desktop\php-5.2.3-Win32&gt;php test2.php

get_object_vars:

iterator(?):

  &gt;&gt; 1: 1

  &gt;&gt; 2: 2







Official PHP 4.3.9 from RHEL4/CentOS4, get_object_vars works:



[root@mailgw1 html]# php test2.php

Content-type: text/html

X-Powered-By: PHP/4.3.9



get_object_vars:

  &gt;&gt; 1: 1

  &gt;&gt; 2: 2

iterator(?):

  &gt;&gt; 1: 1

  &gt;&gt; 2: 2







PHP 5.1.6 compiled from official sources (without any patch) - get_object_vars doesnt work, iterator doesnt work:



[vokac@kmlinux cgi]$ ./php test2.php

X-Powered-By: PHP/5.1.6

Content-type: text/html



get_object_vars:

iterator(?):







Did you try the testing code in you PHP 5.x version? Does it work correctly? I really don&#039;t know what I should do to force get_object_vars work in PHP 5.x





&lt;?php

$a = array(&#039;1&#039; =&gt; 1, &#039;2&#039; =&gt; 2);

$b = (object)$a;

$c = get_object_vars($b);

echo &quot;get_object_vars:\n&quot;;

foreach($c as $name=&gt;$value) {

  echo &quot;  $name: $value\n&quot;;

}

echo &quot;iterator(?):\n&quot;;

foreach($b as $name=&gt;$value) {

  echo &quot;  $name: $value\n&quot;;

}

?&gt;</description> 
   <pubDate>Wed, 08 Aug 2007 03:59:28 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35839</link> 
  </item> 
   
  <item> 
   <title>You live, you learn.  Turns out you can&#039;t have numeric prope</title> 
   <description>You live, you learn.  Turns out you can&#039;t have numeric properties in an object - or more accurately, your property can&#039;t begin with an integer (i.e. you can&#039;t have $obj-&gt;1 or $obj-&gt;1foo).  And it turns out that encoding $msglist as a regular array does return the correct &quot;{&#039;integer&#039;:integer,&#039;integer2&#039;:integer2}&quot; form.  I know for a fact this did not work like this before - but I think the difference now is that we build $msglist ourselves now earlier in the function - and since we are creating the array directly by doing $msglist[integer] calls, PHP is interpreting these indices as string indices.  I can almost guarantee you before we were building via $msglist[], or maybe an array_keys() or array_values() call, or something similar that resulting in the array being created with indexed integers rather than string indices.</description> 
   <pubDate>Wed, 08 Aug 2007 05:36:19 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/5604#t35842</link> 
  </item> 
   
   
 
 </channel> 
</rss> 
