Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For comparing strings I'd recommend using the triple equals operator over double equals.</p> <pre><code>// This evaluates to true (this can be a surprise if you really want 0) if ("0" == false) { // do stuff } // While this evaluates to false if ("0" === false) { // do stuff } </code></pre> <p>For checking the $_GET variable I rather use array_key_exists, isset can return false if the key exists but the content is null</p> <p>something like:</p> <pre><code>$_GET['param'] = null; // This evaluates to false if (isset($_GET['param'])) { // do stuff } // While this evaluates to true if (array_key_exits('param', $_GET)) { // do stuff } </code></pre> <p>When possible avoid doing assignments such as:</p> <pre><code>$myVar = $_GET['param']; </code></pre> <p>$_GET, is user dependant. So the expected key could be available or not. If the key is not available when you access it, a run-time notice will be triggered. This could fill your error log if notices are enabled, or spam your users in the worst case. Just do a simple array_key_exists to check $_GET before referencing the key on it.</p> <pre><code>if (array_key_exists('subject', $_GET) === true) { $subject = $_GET['subject']; } else { // now you can report that the variable was not found echo 'Please select a subject!'; // or simply set a default for it $subject = 'unknown'; } </code></pre> <p>Sources:</p> <p><a href="http://ca.php.net/isset" rel="nofollow">http://ca.php.net/isset</a></p> <p><a href="http://ca.php.net/array_key_exists" rel="nofollow">http://ca.php.net/array_key_exists</a></p> <p><a href="http://php.net/manual/en/language.types.array.php" rel="nofollow">http://php.net/manual/en/language.types.array.php</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload