Re: Object scoping and form variables in PHP4

From: Date: Mon, 14 Aug 2000 23:40:07 +0000
Subject: Re: Object scoping and form variables in PHP4
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-11707@lists.php.net to get a copy of this message
Chris Mayes writes: [snip] > Is there a non-hackish way to import form variables into the object's > scope? Should I send the HTTP_GET/POST_VARS into the object and step > through the hashes (this'd require a property definition for each > variable, but I suppose that's the way objects should be done; it would > just make for a rather tall class definition), or is there a way to > pass the entire local symbol table to the object (which would save me > some logic within each of the objects since PHPLIB would have already > filled the $<name> with each form variable)? I'd also like to avoid > making the whole thing "global" since it's been beaten into my head > since my first programming class that global variables are A Bad Thing. A simple way around would be to do something like this: <?php class foo { var $getvars; var $postvars; var $cookievars; function dump_get_vars() { print_r($this->getvars); } function foo() { /* Don't have to take references, but this way you can change * them if you really want to (perhaps bad?) and no copying * has to happen. */ $this->getvars = &$GLOBALS['HTTP_GET_VARS']; $this->postvars = &$GLOBALS['HTTP_POST_VARS']; $this->cookievars = &$GLOBALS['HTTP_COOKIE_VARS']; } } $foo = new foo(); $foo->dump_get_vars(); ?> > Finally, does anyone know of a searchable archive of this list? I am > going to submit it to Geocrawler in a moment, but that won't really > help for posts that have already happened since (I assume) they don't > start archiving until someone asks them to (though they could just suck > in another archive from somewhere else, I suppose). None of the links > off of php.net seemed to be archived, so I thought I'd ask. > > Thanks! > > -Chris There is a less-than-obvious search box on the www.phpbuilder.com archive page. Personally, I much prefer the archives at http://marc.theaimsgroup.com. YMMV. Cheers, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#11707) next »