Re: The constant use of isset()

From: Date: Tue, 12 May 2009 19:51:38 +0000
Subject: Re: The constant use of isset()
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-43917@lists.php.net to get a copy of this message
On Tue, 2009-05-12 at 19:35 +0000, Ólafur Waage wrote: > On Tue, May 12, 2009 at 5:39 PM, Robert Cummings <robert@interjinn.com>wrote: > > > On Tue, 2009-05-12 at 18:23 +0100, Lewis Wright wrote: > > > Regarding ifsetor, what's wrong with just using this: > > > > > > isset($myvar) OR $myvar = 'i am set'; > > > > > > It works in just the same way and has no problems. I agree it would be > > > great though if there could be a function to retrieve a variable's > > > value if it exists, without throwing an error if it doesn't exist. I'm > > > not sure if isset would be appropriate though. > > > > > > Lewis. > > > > mixed value_of( $variable [, $defaultValue=null] ); > > > > <?php > > > > if( value_of( $_GET['action'] ) == 'edit' ) > > { > > // ... > > } > > > > switch( value_of( $_GET['action'], 'details' ) ) > > { > > case 'details': ... > > } > > > > ?> > > > > Cheers, > > Rob. > > -- > > http://www.interjinn.com > > Application and Templating Framework for PHP > > > > > > Will this run without notices if the value you are passing to the function > isnt set? No, I was suggesting a format for the desired functionality (I should have been more clear). IMHO the above would be the perfect solution if it worked in the same manner as isset() (i.e. doesn't generate notices). Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.internals (#43917) next »