Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4102762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:52:15+00:00 2026-05-20T20:52:15+00:00

I noticed that there are some functions such as is_int() or isset() or file_exists()

  • 0

I noticed that there are some functions such as is_int() or isset() or file_exists() or functions_exists() 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:

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.

or

Does this really worth something to keep checking for file that should exists always?

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.

config.php

$doActions = true;

functions.php

function getID() {
    return $_COOKIE['userid'];
}

class eye {
    public static function see() {
        // gain the object the user is looking at
        return $object;
    }
}

index.php

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->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 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:52:16+00:00Added an answer on May 20, 2026 at 8:52 pm

    This is why languages come with error messages (usually). It won’t just crash silently if something goes wrong, it will tell you. So you can make reasonable assumptions about what you think should always be true, and if it’s ever not true for some reason, you’ll be informed.

    The following checks are useless, IMO:

    1. file_exists – IF the filename is known and you put it there. If the parameter is a variable, then this is OK.
    2. is_bool, is_int, etc. If you insist on the type being correct, use === for comparison. The only one of these I ever use is is_array.
    3. function_exists and the like – if you know the file is there, and you put the function in the file, you can safely assume the function exists. Again, there are special cases where this function is useful – yours is not one of them.

    isset can be useful in some cases, like checking if an array contains a non-null value for a given key, or if a parameter was passed in $_REQUEST. There are other ways of checking that don’t involve isset, but that’s not my point.

    If you can reasonably expect your assertions should true all the time, that it would take a data corruption or huge error on your part to make it false, don’t bother checking. If something does go wrong once in a million tries, then you can catch the error and fix it for next time. The cost to your code readability is too great otherwise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on some code I didn't write and noticed that there are many
I noticed that there's a whole bunch of different content types, some of them
While working on my code lately, I've noticed that some of the memory usage
I was browsing the methods inside of QMainWindow and noticed that some parts (such
I've noticed that some libraries such as clojure-twitter use special vars (the ones intended
I notice that there is some gap after my table. See the following snapshot:
I noticed that there is one change about ASP.NET Routing. I cannot understand why
I've noticed that there seems to be quite a bit of hostility towards Linq
I have noticed that there are strange requests to my website trying to find
In Firebug (with the FirePHP plugin) I noticed that there is no communication with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.