NYCPHP Meetup

NYPHP.org

[nycphp-talk] Is @$arr['key'] ok?

Ben Sgro ben at projectskyline.com
Sat Mar 8 18:50:28 EST 2008


Hello,

Personally, I don't like suppressing warnings, even in this case.

I would think, somewhere previously in your code, when you could have 
set $arr['key'] to a value,
you should (maybe) set it to null (0, empty string, etc) when you create 
it, or somewhere else.

I think it is bad practice to not know if an index is set in array.

Anyways, to answer your questions, I'd vote for the first statement you 
provided.

- Ben

ie:

$arr = array( );
...code...
$arr['key'] = ($something == TRUE) ? null : $somethingElse;

or

$arr['key'] == null;

Michael B Allen wrote:
> Is there any preference for:
>
> $val = isset($arr['key']) ? $arr['key'] : null;
>
> vs:
>
> $val = @$arr['key'];
>
> ?
>
>   



More information about the talk mailing list