PHP: Best Practices for Silent Failure -


i find myself doing lot:

$something = @$_get['else']; if ($something) {     // ... } else {     // ... } 

like, whenever deal arrays. i'm used javascript , ability check falsy value. appropriate in php? trying force php understand, instead of learning own language?

edit

i udnerstand can use isset (i *under*stand it), feels clunky me, , leads clunkier situations i'm trying echo value:

// want echo '<input type="text" name="whatever" value="', @$values['whatever'], '" />';  // fear must echo '<input type="text" name="whatever" value="'; if (isset($values['whatever'])) {     echo $values['whatever']; } echo '" />'; 

setting aside sanitation issue, prefer first version. have sneaking suspiscion it's big no-no. (i have sneaking suspicion don't know how spell "suspicion.")

i recommend never using @ operator. encourages bad code , can make life miserable when doesn't work , you're trying debug it.

you can of course disable notices in php.ini, if start using isset() more :)

you can this:

echo '<input type="text" name="whatever" value="', (isset($values['whatever'])?$values['whatever']:''), '" />'; 

you can read more how horrible @ is, here: http://php.net/manual/en/language.operators.errorcontrol.php

well, it's actual error triggering expensive. using @ triggers error. checking isset() instead, not. http://seanmonstar.com/post/909029460/php-error-suppression-performance


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -