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
There are differences between php5 and php7.
- PHP 5 is released 28 August 2014 but PHP 7 released on 3 December 2015
- It is one of the advantages of the new PHP 7 is the compelling improvement of performance.
- Improved Error Handling
- Supports 64-bit windows systems
- Anonymous Class
- New Operators
On our website you will find industry's best PHP interview questions for freshers.
1. array_combine(): It is used to creates a new array by using the key of one array as keys and using the value of another array as values.
Example :
$array1 = array('key1', 'key2', 'key3'); $array2 = array(('umesh', 'sonu', 'deepak'); $new_array = array_combine($array1, $array2); print_r($new_array);
OUTPUT : Array([key1] => umesh[key2] => sonu[key2] =>deepak)
2. array_merge(): It merges one or more than one array such that the value of one array appended at the end of the first array. If the arrays have the same strings key, then the next value overrides the previous value for that key.
Example :
$array1 = array("one" => "java","two" => "sql"); $array2 = array("one" => "php","three" => "html","four"=>"Me"); $result = array_merge($array1, $array2); print_r($result); Array ( [one] => php [two] => sql [three] => html [four] => Me )
We can use the count() or size() function to get the number of elements or values in an array in PHP.
$element = array("sunday","monday","tuesday");
echo count($element );
echo sizeof($element );
With the help of strip_tags(), we can remove HTML tags from data in PHP.
The strip_tags() function strips a string from HTML, XML, and PHP tags.
strip_tags(string,allow)
The first parameter is required. It specifies the string to check.
The second parameter is optional. It specifies allowable tags. Mention tags will not be removed
$$var is known as reference variable where $var is a normal variable.
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
The error_reporting() function defines which errors are reported.We can modify these errors in php.ini. You can use these given function directly in php file.
error_reporting(E_ALL);
ini_set('display_errors', '1');
It suppresses error messages. It’s not a good habit to use @ because it can cause massive debugging headaches because it will even contain critical errors
It is a PHP library and a command line tool that helps us to send files and also download data over HTTP and FTP. It also supports proxies, and you can transfer data over SSL connections.
Using cURL function module to fetch the abc.in homepage
$ch = curl_init("https://www.bestinterviewquestion.com/");
$fp = fopen("index.php", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Exception handling was introduced in PHP 5 as a new way for the execution of code and what exceptions to make in code in case of a specific error.
There are various keywords of exception handling in PHP like:
Try: This try block consists of the code which could potentially throw an exception. All the code in this try block is executed unless and until an exception is thrown.
Throw: This throw keyword is used to alert the user of a PHP exception occurrence. The runtime will then use the catch statement to handle the exception.
Catch: This keyword is called only when there is an exception in the try block. The code of catch must be such that the exception thrown is handled efficiently.
Finally: This keyword is used in PHP versions 5.5 and above where the code runs only after the try and catch blocks have been executed. The final keyword is useful for situations where a database needs to be closed regardless of the occurrence of an exception and whether it was handled or not.
Note: From the vast number of PHP interview questions, answering this will help you to align yourself as an expert in the subject. This is a very tricky question that often makes developers nervous.
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?