Open In App

PHP Interview Questions and Answers (2024) | Set-2

In this article, you will learn PHP Interview Questions and Answers that are most frequently asked in interviews. Before proceeding to learn PHP Interview Questions and Answers Set 2, first we learn the complete PHP Tutorial and PHP Interview Questions and Answers.

PHP Interview Questions and Answers

PHP is the Hypertext Preprocessor. It is a server-side scripting language designed specifically for web development. It is open-source which means it is free to download and use. It is very simple to learn and use. The files have the extension “.php”.



Pre-requisites

PHP Tutorials
PHP Interview Questions and Answers (2023)

PHP Interview Questions

1. How can you enable error reporting in PHP ?

If you are getting errors and you don’t have idea about those errors then you can use inbuilt error_reporting() function. This function will give you information about those errors where and why it is happening. The best place to include this function is the beginning of your PHP script. You can also set this function for some specific script or you can set it for all the scripts in your server by editing the php.ini file.



2. What is the main error types and how they differ ?

There are various type of errors in PHP but it contains basically four main types of errors.

3. What is inheritance in PHP ?

Inheritance in PHP means the child class can inherit all the properties and protected methods from it’s parent class and extend keyword is used to define the inheritance.

4. Is PHP supports multiple inheritance ?

PHP doesn’t support multiple inheritance but by using Interfaces in PHP or using Traits in PHP instead of classes we can implement it.

5. What are Traits in PHP ?

The trait is a type of class which enables multiple inheritance. Classes, case classes, objects, and traits can all extend no more than one class but can extend multiple traits at the same time.

6. What is difference between GET and POST ?

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

8. If x = 10 and y = “10” then what does the condition x === y returns ?




<?php
$x = 10;  
$y = "10";
  
var_dump($x === $y); 
?> 

It will return bool(false).

9. What is Nullable types in PHP ?

This feature is new to PHP, Nullable adds a leading question mark indicate that a type can also be null.




function geeks(): ?int  {
    return null; // ok
}

10. What is the maximum size of a file that can be uploaded using PHP ?

By default maximum upload file size for PHP scripts is set to 128 megabytes. But you can change it, the maximum size of any file that can be uploaded on a website written in PHP is determined by the values of max_size that can be posted or uploaded, mentioned in the php.ini file of the server. In case of a hosted server need to contact the administrator of the hosting server but XAMPP has interpreters for the scripts written in PHP and Perl. It helps to create a local HTTP server for developers and it provides them full physical and administrative access to the local server. Hence it is the most widely used server and it is very easy to increase the limit on upload files to the desired value in this server.

11. How can we increase the execution time of a PHP script ?

Use PHP inbuilt function ini_set(option, value) where the parameters are the given configuration option and the value to be set. It is used when you need to override the configuration value at run-time. This function is called from your own PHP code and will only affect the script which calls this function. Use init_set(‘max_execution_time’, 0) when you want to set unlimited execution time for the script.




// The program is executed for 3mns. 
<?php 
ini_set('max_execution_time', 180); 
?> 

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

13. What are the three access specifiers Public, Private and Protected in PHP ?

14. Explain the behavior of the spaceship operator ?

The spaceship operator or combined comparison operator is denoted by ““. This is a three-way comparison operator and it can perform greater than, less than and equal comparison between two operands.

15. What are the __construct() and __destruct() methods in a PHP class ?

16. What is urlencode() and urldecode() ?

17. How to remove line breaks from the string ?

The line break can be removed from string by using str_replace() function. The str_replace() function is an inbuilt function in PHP which is used to replace all the occurrences of the search string or array of search strings by replacement string or array of replacement strings in the given string or array respectively.

18. How to remove extension from string ?

There are three ways of removing an extension from the string. They are as follows

19. How to check the value of variable is a number, alphanumeric or empty ?

You can use is_numeric() function to check whether it is a number or not. The ctype_alnum() function is used to check whether it is an alphanumeric value or not and use the empty() function to check variable is empty or not.

20. Is it possible to remove the HTML tags from data ?

Yes it is possible by using the strip_tags() function. This function is an inbuilt function in PHP which is used to strips a string from HTML, and PHP tags. This function returns a string with all NULL bytes, HTML and PHP tags stripped from a given $str.


Article Tags :