Config searchPath error
| From: | Danen Brücker | Date: | Wed, 25 Oct 2006 19:46:05 +0000 |
| Subject: | Config searchPath error | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-25635@lists.php.net to get a copy of this message | ||
Hello!
I'm not sure if this is a bug or a "don't do that", but
Config_Container::searchPath() doesn't seem to work when not starting at
the root.
My config goes somethings like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<datasources default="dbserv-devel">
<datasource name="dbserv-devel">
<type>mysqli</type>
<host>localhost</host>
<user>user</user>
</datasource>
<datasource name="dbserv-live">
<type>mysqli</type>
<host>dbserv</host>
<user>user</user>
</datasource>
</datasources>
</config>
The datasources section contains a single attribute, the name of the
datasource to be used by default. What I've tried to do, is to find this
value (in this case dbserv-devel), then search further into the
datasources tree for the section with that name. The result is an error
unless I start searching all the way from the root element:
[dbrucker@localhost ~]$ php -f test.php
user
PHP Notice: Undefined offset: 0
in /usr/share/pear/Config/Container.php on line 332
PHP Notice: Undefined offset: 1
in /usr/share/pear/Config/Container.php on line 333
PHP Notice: Undefined variable: testFields
in /usr/share/pear/Config/Container.php on line 261
PHP Warning: reset(): Passed variable is not an array or object
in /usr/share/pear/Config/Container.php on line 264
PHP Warning: Invalid argument supplied for foreach()
in /usr/share/pear/Config/Container.php on line 265
PHP Warning: reset(): Passed variable is not an array or object
in /usr/share/pear/Config/Container.php on line 264
PHP Warning: Invalid argument supplied for foreach()
in /usr/share/pear/Config/Container.php on line 265
PHP Warning: reset(): Passed variable is not an array or object
in /usr/share/pear/Config/Container.php on line 264
PHP Warning: Invalid argument supplied for foreach()
in /usr/share/pear/Config/Container.php on line 265
PHP Fatal error: Call to undefined method PEAR_Error::getContent()
in /home/dbrucker/test.php on line 24
The 'test.php' script looks like this:
<?php
require_once( "Config.php" );
$config0 = new Config();
$root =& $config0->parseConfig( './test.xml', 'xml' );
// all the way down works
$dbdevel =& $root->searchPath( array( 'config', 'datasources',
array( 'datasource', array( 'name' => 'dbserv-devel' ) ) ) );
echo $dbdevel->getItem( 'directive', 'user' )->getContent() .
"\n";
$config1 = new Config();
$root =& $config1->parseConfig( './test.xml', 'xml' );
$datasources =& $root->searchPath( array( 'config', 'datasources' ) );
$dbname = $datasources->getAttribute( 'default' );
// fails when not starting at the root
$dbdevel =& $datasources->searchPath( array( 'datasource',
array( 'name' => $dbname ) ) );
echo $dbdevel->getItem( 'directive', 'user')->getContent() .
"\n";
?>
This is with PHP 5.1.6 and PEAR::Config 1.10.7
So, is this an unintended use case of the class? Thanks for any light
shed.