Re: Config recursion error
| From: | Bertrand Mansion | Date: | Sun, 06 Oct 2002 13:04:59 +0000 |
| Subject: | Re: Config recursion error | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-9879@lists.php.net to get a copy of this message | ||
<mike@blueroot.net> wrote :
> I have just updated to config-1.0beta and am testing it with this
>
> require("Config.php");
> $this->config =& new Config("iniFile");
> $content =& $this->config->parseConfig("c:\application\config.ini");
> print_r($content);
>
> There is some kind of error in the generation of the config object - this
> code outputs
>
> config_container_inifile Object
> (
> [type] => section
> [name] => root
> [content] =>
> [children] => Array
> (
> [0] => config_container_inifile Object
> (
> [type] => directive
> [name] => app_width
> [content] => 600
> [children] =>
> [parent] => config_container_inifile Object
> (
> [type] => section
> [name] => root
> [content] =>
> [children] => Array
> *RECURSION*
> [parent] =>
<snip>
> the test ini file is just
>
> []
> app_width = 600
> app_height = 400
>
> [modules]
> testModule = 1
> testModule2 = 1
Because Config works with trees of objects, it is normal to get *RECURSION*
when doing a var_dump or a print_r. PHP is clever in the way it displays its
dumps. If it wasn't that good, it could endlessly display the dump because
in every children there is a reference to its parent.
Instead, it displays *RECURSION*.
Why have such a reference ? Because we need to know at which index in its
parent a child object is, for removes, inserts... And the only way to know
this is (1) keep track of every object index in a separate array (sort of a
directory) (2) have a reference to the child's parent in the child itself.
I choose (2) because it's more fun.
But I thought about those users like me and you who use var_dump() quite
often. There is a toArray() method that should display some kind of dump
when used with var_dump : var_dump($content->toArray());
Anyway, thanks for the feedback, don't hesitate to report any other bugs or
malfunction.
Bertrand Mansion
Mamasam