Re: Newbie: Do or Die ... howto in PHP???

From: Date: Mon, 07 Apr 2003 22:28:49 +0000
Subject: Re: Newbie: Do or Die ... howto in PHP???
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-142761@lists.php.net to get a copy of this message
On Mon, 7 Apr 2003 15:29:33 +1000, Tom Rogers wrote about "Re: [PHP] Newbie: Do or Die ... howto in PHP???" what the universal translator turned into this: >To cut down typing I use this class in an auto prepend file. > >class req { > function get($var,$sub=False){ > return (isset($_GET[$var]))? $_GET[$var]:$sub; > } > function post($var,$sub=False){ > return (isset($_POST[$var]))? $_POST[$var]:$sub; > } > function request($var,$sub=False){ > return (isset($_REQUEST[$var]))? $_REQUEST[$var]:$sub; > } > function server($var,$sub=False){ > return (isset($_SERVER[$var]))? $_SERVER[$var]:$sub; > } > function session($var,$sub=False){ > return (isset($_SESSION[$var]))? $_SESSION[$var]:$sub; > } >} > >No need to instantiate the class just use like this > >if($loc = req::get('loc'){ > $includefile("files/$loc.src.html"); >} >else { > $includefile('files/defaultfile.src.html'); >} > >you can also supply a default value like this: > >$file = req::get('loc','defaultfile').'.src.html'; >incluse{$file); > >If you get variables by both post or get use req::request('var') > >Not exactly what you asked for but it should help It's a bit overkill for my situation I think ... All I want is a simpler way of assigning the default value to a variable, in case it's not set ... It's more to make the code more efficient, and easier to overlook ... when you've got multiple layers of if-blocks within if-blocks, it tends to get a bit messy after a while... Rene -- Rene Brehmer This message was written on 100% recycled spam. Come see! My brand new site is now online! http://www.metalbunny.net

« previous php.general (#142761) next »