PHP Interview Question #1
What’s the difference between the
they both include a specific file but on require the process exits with a fatal error if the file can’t be included, while include statement may still pass and jump to the next step in the execution.
PHP Interview Question #2
How can we get the IP address of the client?
This question might show an interview how playful and creative the candidate is because there are many options.
$_SERVER["REMOTE_ADDR"]; is the easiest solution, but you can write x line scripts for this question.
PHP Interview Question #3
What’s the difference between
unset() sets a variable to “
unlink() deletes a file we pass to it from the file system.
PHP Interview Question #4
What is the output of the following code:
$a = '1'; $b = &$a; $b = "2$b"; echo $a.", ".$b;
The answer is
PHP Interview Question #5
What are the main error types in PHP and how do they differ?
In PHP there are three main type of errors:
Notices – Simple, non-critical errors that are occurred during the script execution. An example of a Notice would be accessing an undefined variable.
Warnings – more important errors than Notices, however the scripts continue the execution. An example would be
include() a file that does not exist.
Fatal – this type of error causes a termination of the script execution when it occurs. An example of a Fatal error would be accessing a property of a non-existent object or
require() a non-existent file.
Understanding the error types is very important if you are new to programming because they help you understand what is going on during the development, and they will help you know what you should look for in the code during debugging.
PHP Interview Question #6
What is the difference between
– GET displays the submitted data as part of the URL, during POST this information is not shown as it’s encoded in the request.
– GET can handle a maximum of 2048 characters, POST has no such restrictions.
– GET allows only ASCII data, POST has no restrictions, binary data are also allowed.
– Normally GET is used to retrieve data while POST to insert and update.
Understanding the fundamentals of the HTTP protocol is very important to have a good start as a PHP developer, and the differences between GET and POST are an essential part of it.
PHP Interview Question #7
How can you enable error reporting in PHP?
Check if “
display_errors” is equal “on” in the php.ini or declare “
ini_set('display_errors', 1)” in your script.
Then, include “
error_reporting(E_ALL)” in your code to display all types of error messages during the script execution.
Enabling error messages is very important especially during the debugging process as you can instantly get the exact line that is producing the error and you can see also if the script in general is behaving correctly.
PHP Interview Question #8
What are Traits?
Traits are a mechanism that allows you to create reusable code in languages like PHP where multiple inheritance is not supported. A Trait cannot be instantiated on its own.
It’s important that a developer know the powerful features of the language (s)he is working on, and Trait is one of such features.
PHP Interview Question #9
Can the value of a constant change during the script’s execution?
No, the value of a constant cannot be changed once it’s declared during the PHP execution.
PHP Interview Question #10
Can you extend a
Final defined class?
No, you cannot extend a
Final defined class. A
Final class or method declaration prevents child class or method overriding.
PHP Interview Question #11
What are the
__destruct() methods in a PHP class?
All objects in PHP have Constructor and Destructor methods built-in. The Constructor method is called immediately after a new instance of the class is being created, and it’s used to initialize class properties. The Destructor method takes no parameters.
Understanding these two in PHP means that the candidate knows the very basics of OOP in PHP.
PHP Interview Question #12
How we can get the number of elements in an array?
count() function is used to return the number of elements in an array.
Understanding of arrays and array related helper functions it’s a knowledge that every junior developer should have."This article is writer’s personal opinion and doesn’t represent Organization Policy. This blog is for students and teachers of Career Institute and they can have their own views on different topics."