PHP Interview Questions and Answers
PHP earlier stood for Personal Home Pages, but now it stands for Hypertext Pre-processor. PHP is a server-side scripting language that is used for building web pages and applications. We have just added more questions in our question bank for PHP interview questions. This language includes many Frameworks and CMS for creating large websites. Even a non-technical person can create web pages or apps using PHP CMS or frameworks. PHP supports various frameworks and CMS that are used to develop applications.
Before getting confused with the plethora of PHP developer interview questions, you need to ensure the basics. This question will help you to understand the core basics of PHP and make you even more confident enough to jump onto the advanced questions.
Quick Facts About PHP | |
---|---|
What is the latest version of PHP? | 8.0.3, released on 4th March 2021 |
Who is the developer of PHP? | Rasmus Lerdorf |
What language does PHP use? | C language |
PHP License | It is a BSD-style license which does not have the "copyleft" and restrictions associated with GPL. |
- It runs on various platforms, including Windows, Mac OS X, Linux, Unix, etc.
- It is compatible with almost all servers, including Apache and IIS.
- It supports many databases like MySQL, MongoDB, etc
- It is free, easy to learn and runs on the server-side.
- PHP can operate various file operations on the server
Note: This is a list of the most frequently asked PHP interview questions. Please have a good read and if you want to download it, it is available in a PDF format so that you can brush up your theoretical skills on this subject.
Top PHP Developer Interview Questions
PHP earlier stood for Personal Home Pages, but now it stands for Hypertext Pre-processor. PHP is a server-side scripting language that is used for building web pages and applications. This language includes many Frameworks and CMS for creating large websites.
Even a non-technical person can create web pages or apps using PHP CMS. PHP Supports various CMS like WordPress, Joomla, Drupal and Frameworks like Laravel, CakePHP, Symfony, etc
A trait is a group of various methods that reuse in single inheritance. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of processes. We can combine traits and classes to reduce complexity, avoid problems typically associated with Mixins and multiple inheritances.
trait HelloWorld
{
use Hello, World;
}
class MyWorld
{
use HelloWorld;
}
$world = new MyWorld();
echo $world->sayHello() . " " . $world->sayWorld(); //Hello World
Magic methods are unique names, starts with two underscores, which denote means which will be triggered in response to particular PHP events.
The magic methods available in PHP are given below:-
- __construct()
- __destruct()
- __call()
- __get()
- __unset()
- __autoload()
- __set()
- __isset()
Note: One of the most tricky oops interview questions in php, you need to answer this question with utmost clarity. Maybe explaining it with a short example or even a dry run would help you get that dream job.
These all are PHP Operators.
- = is used to assign value in variables. It is also called assignments operators.
- == is used to check if the benefits of the two operands are equal or not.
- === is used checks the values as well as its data type.
require() | include() |
---|---|
If a required file not found, it will through a fatal error & stops the code execution | If an essential file not found, It will produce a warning and execute the remaining scripts. |
In PHP header() is used to send a raw HTTP header. It must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP
Example :
header(string,replace,http_response_code);
1. string: It is the required parameters. It specifies the header string to send.
2. replace: It is optional. It indicates whether the header should replace previous or add a second header.
3. http_response_code : It is optional. It forces the HTTP response code to the specified value
PHP has three access modifiers such as public, private, and protected.
public
scope of this variable or function is available from anywhere, other classes, and instances of the object.private
scope of this variable or function is available in its class only.protected
scope of this variable or function is available in all classes that extend the current class including the parent class.
Note: One of the most tricky oops interview questions in php, you need to answer this question with utmost clarity. Maybe explaining it with a short example or even a dry run would help you get that dream job.
- InnoDB
- CSV
- MEMORY
- ARCHIVE
- MyISAM
With PHP 5.6+ "InnoDB" is treated by default database storage engine. Before that MyISAM defaulted storage engine.
There are lots of differences between storage engines. Some are given below:-
- MyISAM supports Table-level Locking, but InnoDB supports Row-level Locking
- MyISAM designed for the need of speed but InnoDB designed for maximum performance when processing a high volume of data
- MyISAM does not support foreign keys, but InnoDB supports foreign keys
- MyISAM supports full-text search, but InnoDB does not support this
- MyISAM does not support the transaction, but InnoDB supports transaction
- You cannot commit and rollback with MyISAM, but You can determine and rollback with InnoDB
- MyISAM stores its data, tables, and indexes in disk space using separate three different files, but InnoDB stores its indexes and tables in a tablespace
Note This is a good question concerning PHP interview questions for experienced.
If we used $_SERVER[‘REMOTE_ADDR’] to get an IP address, but sometimes it will not return the correct value. If the client is connected with the Internet through Proxy Server then $_SERVER[‘REMOTE_ADDR’] in PHP, it returns the IP address of the proxy server not of the user’s machine.
So here is a simple function in PHP to find the real IP address of the user’s machine.
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Top 10 PHP Interview Questions
Here you will find the list of Top PHP interview questions, which were written under the supervision of industry experts. These are the most common questions and usually asked in every interview for the role of the PHP Developers.
- What are Design Patterns in PHP?
- What is the difference between abstract class & interface in PHP.
- What is traits & how it can we used?
- What is the use of .htaccess file?
- What is the difference between MyISAM and InnoDB?
- What is the difference between Public Private and Protected?
- What is Constructor and Destructor?
- What is final class and final method in PHP?
- What is a static member function?
- What is function Overloading and Overriding in PHP?