I noticed that there are some functions, such as is_int() or isset() or file_exists() or functions_exists() , which are somehow very useful. When I write code, I always think of any bad things that can happen to my site, but sometimes I encounter problems such as:
Wait, this variable is being set inside the PHP file; that means no one can edit it, right? And if this βuserβ could edit it, I would have more trouble because he could manage the PHP file.
or
Is it really worth it to constantly check the file, which should always exist?
Let's look at the following example, which does not make sense on its own, but helps me to make you understand what I'm talking about. PS: I specifically exaggerated the code.
config.php
$doActions = true;
functions.php
function getID() { return $_COOKIE['userid']; } class eye { public static function see() {
index.php
class viewer { private $poniesSeen = 0; public function __construct() { } 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->poniesSeen) and is_int($this->poniesSeen)) { ++$this->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; } } }
Now, I think, which of these conditions should be preserved and what should be thrown away, because they have no meaning? Why shouldn't I check them and why? Is there a golden rule about these obsessions?
source share