PHP Advanced Interview Questions and Answers For Experienced

We brought here some advanced PHP interview questions that need special attention while preparing for an Interview.

We have collected these questions and answers from various sources and candidates have been appeared in multiple PHP Developer Interviews.

These questions are useful for Freshers searching jobs for PHP developers and also for the people looking for a change having 2+ years experience.

These are not pure practicle based questions but they have a huge impact on your selection for the right job.

How we can set default time-zone in PHP?

Using library function date_default_timezone_set() we can set default time-zone:

<?php date_default_timezone_set("America/New_York"); echo "Time in Default Zone is : " . date("h:i:sa"); ?>

What is difference between == and === ?

Both are the comparison operator. The first one (==) is ‘Equal to’ and the second one (===) is ‘identical to’. ‘Equal to’ is used to compare the values of variables. ‘Identical to’ is used to compare values as well as the type of variables.

For Example :

<?php $x = 1250; $y = '1250'; if($x==$y){ echo 'X and Y are Equal'; }else{ echo 'X and Y are Not equal'; } if($x===$y){ echo 'X and Y are Identical'; }else{ echo 'X and Y are Not Identical'; } ?>

What is difference between != and !== ?

Both are the comparison operator. The first one (!=) is ‘Not Equal’ and second one (!==) is ‘Not identical’. ‘Not equal’ is used to compare the values of variables. ‘Not Identical’ is used to compare values as well as the type of variables.

For Example :

<?php $x = 1250; $y = '1250'; if($x!=$y){ echo 'X and Y are Not equal'; }else{ echo 'X and Y are Equal'; } if($x!==$y){ echo 'X and Y are Not Identical'; }else{ echo 'X and Y are Identical'; } ?>

How do I get PHP errors to display?

Use the following code snippet to on error reporting in PHP script:

<?php 
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);

But we can not display PHP parse error this way. We need to modify php.ini file and need to ‘on’ the display error:

display_errors = on

What is difference between Notice Errors and Warning Errors in PHP?

Notice and Warning are the Non-fatal Errors and Not let the script halted.
Notice is an Advisory message regarding what you should prefer to do with this line of code.
For example using an undefined variable is a Notice.

notice-error-phpWarning is the message saying that you are going wrong and that may cause an error in future so , you may correct that. For example including a not existing script will throw a Warning.
warning-error-php

What is the use of break and continue in PHP loop?

Break : It terminates the loop and exit from the iteration.

Continue : It escape the current iteration and starts new iteration in the loop.

What are common types of errors that occurs in Php execution?

Php has Identified numbers of Error detection categories. Following are the common errors in PHP:

E_ERROR : A fatal error and halts the script from further execution.

E_WARNING: Run time warning that detects something is wrong that you need to correct to avoid future errors.

E_PARSE : Compilation error when the code is parsed. We need to on the error reporting in php.ini file to get this.

E_NOTICE: Run time notice to notify that you should go follow the suggested message.

E_CORE_ERROR: It is a fatal error that halts the script and occurs at the initial startup of PHP.

E_CORE_WARNING : Warnings that occurs at the initial startup of PHP.

E_COMPILE_ERROR : Fatal error on compilation occurs at the initial startup of PHP.

E_USER_ERROR : User-generated error message.

E_USER_WARNING : User-generated warning message.

E_USER_NOTICE : User-generated notice message.

E_STRICT : Run-time notices.

E_RECOVERABLE_ERROR : Catchable fatal error indicating a dangerous error

E_ALL : Catches all errors and warnings

Difference between mysql_connect and mysql_pconnect?

When mysql_pconnect() is used to create and maintain a persistent connection to the database that means a SQL link that does not close when the execution of your script ends whereas mysql_connect() creates a new connection each time when it called.

When a persistent connection is created and again a connection request is called the mysql_pconnect() return the earlier established connection rather than creating a new instance of connection.

What do you understand by &$name ?

Using the reference of the variable rather than a copy of that.

If we pass the reference of a variable in a function as an argument and the value is changed then the value of the original variable outside the function is also changed.

This is passing by reference.

What is New in PHP 7?

PHP 7 has many new features. Here is the list of PHP 7 New features:

  • Scalar type declarations
  • Return type declarations
  • Null coalescing operator
  • Spaceship operator
  • Constant arrays using define()
  • Anonymous classes
  • Unicode codepoint escape syntax
  • Closure::call()
  • Group use declarations

When you are going for a PHP Developer job you should also focus on Jquery Interview Questions, PHP-MySQL Interview Questions, PHP Functions asked in Interviews.
I hope you enjoyed learning. You can ask any question based on the Above topic or you can submit questions here in the comment box.

Dhananjay

Dhananjay

I’m Dhananjay — a free-spirit with a passion for technologies and blogging.

View all posts by Dhananjay →

4 thoughts on “PHP Advanced Interview Questions and Answers For Experienced

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.