PHP Interview Questions with Solutions

I’m taking another course on Udemy, this time about PHP interview questions. I’m gonna have an interview next week and i need to refresh my memory with common PHP interview questions. Honestly i was looking for a senior level course but this is the best i could find. Of course there are loads of information on the web for interview questions but i prefer Udemy courses 🙂

So… let’s start.

What is the difference between the include() and require() functions?

Both are used to include files inside current file. In case of include() if the file is not found just a warning will be thrown and the rest of the code will be executed. In case of require if the file is not found again a warning will be thrown but also a fatal error which prevents the rest of the code execution.

What is the difference between unlink() and unset() functions?

The unlink() function is used for file system handling and it simply deletes the file if it is able to do so (if the service running the PHP script has delete permissions over the file). It returns true on success or false otherwise. The unset() function is used for variable management and it will make the variable undefined.

The main error types in PHP and how do they differ?

There are three main error types in PHP: notices, warnings and fatal errors. Notices are non-critical and usually occur when undefined variables are being used; by default notices are not visible to the users. Warnings are more serious than notices but both of them do not affect the script execution. Warnings can appear for example when the script tries to include a file which it cannot find. By default warnings are visible to the user. Fatal errors are critical errors and they stop the execution of the script immediately. For example a fatal error can occur if we try to call a function that does not exist.

What is the difference between $_GET and $_POST?

GET and POST methods are the two main means by which we can send information from one page to another. PHP has two variables which are available anywhere in the script and are called superglobals. The information available in the $_GET variable is populated from the so called query string of the URL ( GET requests remain in the browser history and should not be used for sending sensitive data like passwords. GET also has size limitations depending from one browser to another. In the case of POST requests the data is sent in the HTTP message body and it is not visible to the user thus is a secure method to send information across the web. And unlike GET, POST is never cached, does not remain in the browser history and it can send theoretically any size of data.

How can you enable error reporting in PHP?

error_reporting() function is used to report an error in PHP. One can set error reporting in the PHP configuration file (php.ini file) or by using error_reporting() function. For example: error_reporting(0) turns off any kind of errors; error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE) turns on the reporting of all errors; error_reporting(E_ALL) also turns on all errors; error_reporting(E_ALL & ~E_NOTICE) turns on all errors except notice and error_reporting(-1) turns on all errors.

I barely made it to 20% of the course and i got bored. For the first time i won’t recommend a Udemy course, this course, unless you are interested in the basics. This course is perfect for junior developers but i’m a senior so i need more challenging courses. So i just asked for a refund 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.