What is the difference between @include and include?

Hello!
Maybe a silly question, but interested in me for a long time, information Google not issued. Please tell me what is the difference, to put @ before the include statement or not?
September 19th 19 at 12:11
2 answers
September 19th 19 at 12:13
Solution
  1. The dog has nothing to include. It is not a single operator and two different operators.
  2. Seeing @ in the code you can almost with absolute certainty say that it was written illiterate user, and use this code it is not necessary.
  3. Seeing in the code with@include you can safely assume the author an absolute sucker and a noob, and the code itself should be thrown out immediately. Because @include jamming not only the error include the file, but all the errors in this file - that is, it comes a hundred times worse. This means that if the author permits such schools in your code, and everything else he is also hell.
  4. The most important thing. Errors must not be suppressed. Errors need to be corrected. But again, do it wisely. Novice programmers think error messages are his personal enemies, and fight them by all means available - through @, error_reporting(0) etc. after Receiving the ruler's hands and remembering for life, so to do, vincenot with no less zeal to write all sorts of checks - but would not allow, God forbid, the hated of the error message. For example:

if (file_exists($inc))
{
 include $inc;
} else {
 echo "File not found";
}

Now, this is even worse. For starters, part of the error this code still does not catch. But it's not even the most important thing. The main thing - that this is now "File not found" has not the slightest sense. To the user it will not say anything. And the programmer won't know about it. But if someone did, they won't understand! Which file? Where it is not found? For what reason? The system error message contains a lot of invaluable information helps you to identify the error, telling us where it happened, what kind of file not found why not found. To give instead of the stub "file not found" - it's masochism.

And here we must make a genuine revolution in the immature child's brain: the error message is not your enemy and your friend! And we must fight its occurrence in all possible ways! Including the sawing of pointless checks. The test can be put only if we have the script handle the error: for example, instead of the file we can toincluding some other default. Then Yes - check makes sense. But if this is the most common include, which should always be in place, then his absence shall cause an error! She was immediately shown on the dev server and then corrected. She was recorded in the log on the production, and then corrected.

Error it is not necessary to suppress. Errors do not need to hide. Errors need to be corrected.
Now I understand why search engines need no results returned, even thought to look for something special about @. Thanks, comprehensive answer. - Cierra.Weber commented on September 19th 19 at 12:16
@ weapon soton - carrie_Windl commented on September 19th 19 at 12:19
A small opus on the subject:
In the above code there is a bug with race condition (during include file may not already exist since it uses a set of consecutive opcodes, and php, remind, often working in multi-threaded mode), important for highly loaded systems. And if you have dogs and have error handling (this is important! Bugs still need to catch. or not put out at all) this can be avoided (honestly, no idea how that gash in the example). The point is that it is not necessary to be so categorical, it is certainly evil, but it must be very skillfully used to benefit. - jordi.Denesik commented on September 19th 19 at 12:22
September 19th 19 at 12:15
Solution
Bad difference. @ suppresses error output, i.e. in this case it will not show an error that file does not exist. Better really check there is a file or not.
But if the display of errors turned off, there is no difference? - Cierra.Weber commented on September 19th 19 at 12:18
: it is even worse. On the local error should be shown in any case, plus entry to the log so you can catch errors on pages redirect. To combat shows no error, but write to the log. Tomorrow you site will be a blank page to give, then you will tear your hair in one place. And so I looked in the log, I realized that someone knocked down the file and returned it back quickly. - carrie_Windl commented on September 19th 19 at 12:21
: that is, in the case of @ error in the log is also not recorded? - jordi.Denesik commented on September 19th 19 at 12:24
: I'll record tomorrow. @ generally a very bad practice. It is better to check all the data themselves. @ Russian "Avos". If your project will work for the best, then maintain it will be very difficult. - Cierra.Weber commented on September 19th 19 at 12:27
: okay, thanks for the help. - keshaun_Kub commented on September 19th 19 at 12:30

Find more questions by tags PHP