All PHP Interview Questions & Answers

All PHP Interview Questions & Answers list

Here, you can find PHP Interview Questions & Answers related to Arrays, Operators, Loops, Variables, Conditional Statements, Strings, Form, MySQL, Cookies, and Sessions. These popular & frequently asked interview questions are listed under different categories.

Tutorials Class covers Interview Questions for Freshers as well as Experienced professionals. We not only list core PHP but also provide Advanced PHP interview questions for students.

What is single line comment in PHP? Explain with syntax.

The single line comment tells the interpreter to ignore everything that occurs on that line to the right of the comment. To do a single line comment type // or # and all text to the right will be ignored by PHP interpreter.

Example of single line comment


How you can force maximum execution time error in PHP?

We can use sleep function to consume PHP execution time and it will throw PHP error.


Output:

maximum execution time error in php


How can we set infinite execution time in PHP Script ?

By adding the set_time_limit(0) at the beginning of PHP script, we can set the infinite execution time for PHP Script. Note: This method will only work if you are allowed to change PHP configuration by Hosting Server.


How to increase maximum execution time in PHP and WordPress

We mostly see that the maximum execution time of a PHP Script is 30 seconds. If a script takes more than 30 seconds to execute, it will throw the following Fatal error.
Fatal error: Maximum execution time of 30 seconds exceeded in ....

We can increase maximum execution time in PHP and WordPress by using various methods. In the following examples, we have increased maximum execution time to 360 seconds (6 minutes).

Method 1: By adding the code in a PHP file:

We can set the maximum execution time by adding this code in a PHP File. You must add this code in that file which is included earlier in all other pages. Then this function will increase maximum execution time in all those files.
For example, put this code in header (header.php), or configuration (config.php) if available.


Method 2: Inside the .htaccess file:

We can do the same thing inside the .htaccess file as well. Before editing this file, you make sure to have a backup of .htaccess.


Method 3: Inside the php.ini file:

We can also set the maximum execution time by adding this code in the php.ini file.


Method 4: Inside wp-config.php file in WordPress:

If you are using WordPress then you can place this code in wp-config.php file.


Note: These methods will only work if you are allowed to change PHP configuration by your Hosting Server.


What is the difference between == and === Operators in PHP?

PHP equal operator (==) and idential operator (===) are Relational or Comparison Operators in PHP langauge.

The only difference is that === operator matches the values along with Data types. While == operator only match values but not Data types.


Example to see difference between both operators

We have compared the two variable one by one by using == and === Operator, we get the following result.

You will see that value is matched if used the equal operator ‘==’ and not matched if used identical operator ‘===’ because data type is not same for both numbers.

Therefore, if we need to match both values strictly with datatypes, ‘===’ operator will be used else ‘==’ will be used in PHP.