NYCPHP Meetup

NYPHP.org

[nycphp-talk] XML <-> Globals

Hans Zaunere hans at nyphp.org
Wed Jul 9 15:18:02 EDT 2003



Jon Baer wrote:

> im trying to attempt to dump some properties for an application into an xml
> file that looks as such:
> 
> <?xml version="1.0" ?>
> <register>
>  <global name="foo">bar</global>
>  <global name="name">jon baer</global>
>  <global name="prefix">00:30:00</global>
> </register>
> 
> and using phpxmlclasses ...
> 
> <?
> include_once("class_path_parser.php");
> 
> function register($name,$attribs,$content) {
>   $key = $attribs['name'];
>   echo("Key: $key Value: $content<br/>");
> }
> 
> $parser = new Path_parser();
> $parser->set_handler("/register/global","register");
> if(!$parser->parse_file("globals.xml")) {
>   print("Error:".$parser->get_error()."<br/>\n");
> }
> ?>
> 
> what id like to end up w/ is a common file that all my objects/pages can
> read and dump into something like $_XML['foo'] similar to the other
> predefined variables.  what is the best method to attempt this if i want my
> order to go as such:  XML->SESSION->POST->GET->etc.

AFAIK, you can't create your own, true, superglobals.  Thus, there'd be no way to specify the variables_order for an userland var like $_XML (since it's not really a superglobal)

> im trying to do the same with $_REMOTE['foo'] to read a connection if it can
> be made.
> 
> if i place it in the auto_include (php.ini) would this work?

Yeah, but even an auto_included file is much later than when the real superglobals get created.  To emulate user defined superglobals at runtime, I've done the nasty:

$_SERVER['XML'] = array('new','york','php');

function foo() {
   echo implode('-',$_SERVER['XML']);    new-york-php
}


Which keeps an array named XML out of the global namespace; otherwise, $GLOBALS is probably best.


H





More information about the talk mailing list