Re: Error suppression operator (@)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Pretty much the only time i use it is form processing... so i don't get a 
bunch of errors when someone doesn't fill out a (non-required) field..
Also i use it to prefill form data is i have a session running, ie.

<input name="fname" type="text" value"<?php echo @$_SESSION['APP']['fname']; 
?>" />

like others have mentioned... if there is no value, the form is blank, 
otherwise the value is used as its defualt value... pretty neat!

Colin

On 5/4/05, Jochem Maas <jochem@xxxxxxxxxxxxx> wrote:
> 
> Greg Donald wrote:
> > On 5/3/05, GamblerZG <gambler@xxxxxxxxxxxxxx> wrote:
> >
> >>I would like to know, whether using @ is a good practice.
> >
> >
> > I try not to use it much, but when I do I back it up with checking to
> > see if an error really occured. I use it for file handles, database
> > handles, stuff that I really expect to break sometimes. I don't ever
> > use it to assist with sloppy coding style, not defining variables and
> > such. In fact I always code with error_reporting( E_ALL ) until I
> > take the code into production.
> >
> 
> Greg makes some good points. in short don't use @ lightly,
> in theory you are never required to use it at all.
> 
> in some situations you may have an intensive/heavy function or
> loop which access array items (inside the loop) which may or
> may not be set... in such cases you may find you want/need to
> try and optimize....
> 
> foreach($arr1 as $a) {
> // if (isset($arr2[ $a ])) {
> if (@$arr2[ $a ]) {
> // ...
> }
> // ...
> }
> 
> this example assumes that $arr2 is an array and that every
> item you are checking will cast to boolean true (e.g. the
> value 0 will cast to false) -- so on a few occasions you
> can 'cheat' with the @ and grab a cycle or 2, but be
> very careful what you are doing.
> 
> have fun :-)
> 
> >
> >>For example, I
> >>have an array of unknown length $array.
> >>Is it all right write something like this:
> >>
> >>@list($first, $second) = $array;
> >
> >
> > I go with $array[0], $array[1] and such. Or maybe
> >
> > while( list( $k, $v ) = each( $array ) )
> > {
> >
> > }
> >
> >
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux