Re: Construct Request

From: Date: Thu, 15 Apr 2004 20:20:03 +0000
Subject: Re: Construct Request
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-9223@lists.php.net to get a copy of this message
You can avoid the E_NOTICE using a reference, but it can have undesired side effects. For example, if you pass $x[5] by reference (whether to an internal function or a user defined function), $x[5] will be "created" and set to NULL. To avoid this side-effect, don't use the reference and instead use @$x[5] as the first argument to the function. (but DO NOT use @$x[5] as an argument to a function that takes a reference - it may cause a crash/corruption later.) - Todd On Thu, 2004-04-15 at 13:14, Jason Garber wrote: > >I wrote this (I underlined the relevant parts for you): > > > > > >You'll need something more clever, because > > > >an undefined key 'CUST_ID' in $_POST['CUST_ID'] will strill > > > >throw a > > > Consider this: > > ----------------------------------- > <?php > > error_reporting(E_ALL); > > function setor(&$param, $default) > { > return (isset($param) ? $param : $default); > } > > > $x = setor($x, 10); ///Should Produce an E_NOTICE > > echo gettype($x) . ':' . $x . "\n"; > > ?> > ----------------------------------- > > This DOES NOT produce an E_NOTICE like you said (notice the &). However, > $param1 is defined and NULL inside the function, even though $x was not a > defined variable outside the function?? > > ~Jason

« previous php.internals (#9223) next »