PHP Interview Questions for Experience –
Question 1 – Please Define Magic method in PHP?
Answer – A magic methods are special built-in methods that are called automatically when certain conditions are met in PHP.
Every magic method starts with a double underscore ( __ ) in PHP.
PHP has several magic methods as –
- __construct()
- __set()
- __destruct()
- __debugInfo()
- __toString()
- __get() etc…
Question 2 – What are the different types errors in PHP?
Answer -PHP has main 3 types of errors given as follows-
- Warning: In PHP, a warning is an error that is displayed to the programmer while the script is running.
- Notice: A notice is not error. It is not displayed to the programmer.
- Fatal error: Fatal error is the most critical type of error. It will cause immediate termination of the script/program.
Question 3 – How will you get the IP address of user in PHP?
Answer – $_SERVER[‘REMOTE_ADDR’].
It is super global variable of PHP.
Question 4 – What do you understand about LAMP?
Answer – LAMP stand for Linux, Apache, MySQL and PHP. It is a Open Source Web Server for developing the web applications such as XAMPP.
Question 5 – How can you destroy the session and unset the variable of a session in PHP?
Answer –
<?php
session_destroy(); // destroy session
session_unset(); // remove all session variables
?>
Question 6 – How will you submit form without a submit button?
Answer – Using JavaScript code, we can call the document.form.submit() function to submit the form.
Question 7 – What are the different type of tables in mysql?
Answer –
- MyISAM
- Merge
- Heap
- InnoDB
- BDB
- ISAM
Question 8 – How can you enable error reporting in PHP?
Answer –
- First we check “display_errors” is “on” in the php.ini or
- declare “ini_set(‘display_errors’, 1)” in our script.
- Then, include “
error_reporting(E_ALL)
” in your code.
The above code will displayed all types of error messages.
Question 9 – You can change the value of a constant during the script’s execution?
Answer – No, A constant value cannot change if it’s declared during the PHP execution.
Question 10 – How can you get the number of elements in an array?
Answer – Using count() function –
<?php
$names=array("Ashok","Shivam","Haq"); // array
echo count($names); // the output is 3
?>
PHP Interview Questions for 3 Years Experience