Note that there are some explanatory texts on larger screens.

plurals
  1. PODeveloping strong applications
    text
    copied!<p>I noticed that there are some functions such as <code>is_int()</code> or <code>isset()</code> or <code>file_exists()</code> or <code>functions_exists()</code> that are somehow very useful. When I write some code I do always think to every bad things that could happen to my site, but sometime I face problems such as:</p> <blockquote> <p>Wait, this variable is set inside the PHP file; this means that no one could ever edit it, right? And if this "user" could edit it I would have a lot of more troubles because it would be able to manage the PHP file.</p> </blockquote> <p>or </p> <blockquote> <p>Does this really worth something to keep checking for file that should exists always?</p> </blockquote> <p>Let's consider the following example which has no sense by its own, but will help me in order to make you understand what I'm talking about. PS: I exaggerated the code on purpose.</p> <p><strong>config.php</strong></p> <pre><code>$doActions = true; </code></pre> <p><strong>functions.php</strong></p> <pre><code>function getID() { return $_COOKIE['userid']; } class eye { public static function see() { // gain the object the user is looking at return $object; } } </code></pre> <p><strong>index.php</strong></p> <pre><code>class viewer { private $poniesSeen = 0; public function __construct() { /* Magic ponies are created here */ } public function sawAPony($id) { if (file_exists('config.php')) { if (isset($doActions)) { if (is_bool($doActions)) { if ($doActions) { if (file_exists('functions.php')) { if (function_exists('getID')) { $id = getID(); if (!empty($id)) { if (!is_int($id)) { settype($id, 'int'); } if (class_exists('eye')) { if (method_exists('eye', 'see')) { $o = eye::see(); if (is_string($o)) { if ($o = 'pony') { if (isset($this-&gt;poniesSeen) and is_int($this-&gt;poniesSeen)) { ++$this-&gt;poniesSeen; return true; } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } } } </code></pre> <p>Now, I think, which of this conditions should be kept and what thrown away because they have no sense at all? Why should I not check for them and why should I? Is there a golden-rule about this kind of obsessions?</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