PHP: Hypertext Preprocessor is open source server-side scripting language that is widely used for creation of dynamic web applications.It was developed by Rasmus Lerdorf also know as Father of PHP in 1994.
PHP is a loosely typed language , we didn’t have to tell PHP which kind of Datatype a Variable is. PHP automatically converts the variable to the correct datatype , depending on its value.
Today we are going to discuss some good interview questions and answers on PHP.
Top PHP interview questions and answers
Below are the few Latest Php programming interview questions
- What is PHP ?
PHP: Hypertext Preprocessor is open source server-side scripting language that is widely used for creation of dynamic web applications.It was developed by Rasmus Lerdorf also know as Father of PHP in 1994.
PHP is a loosely typed language , we didn’t have to tell PHP which kind of Datatype a Variable is. PHP automatically converts the variable to the correct datatype , depending on its value.
- What is T_PAAMAYIM_NEKUDOTAYIM ?
T_PAAMAYIM_NEKUDOTAYIM is scope resolution operator used as :: (double colon) .Basically it used to calling static methods/variables of a Class.
Example usage:-
$Cache::getConfig($key);
3. What is the difference between == and === operator in PHP ?
In PHP == is equal operator and returns TRUE if $a is equal to $b after type juggling and === is Identical operator and return TRUE if $a is equal to $b, and they are of the same data type.
Example Usages:
- What is session in PHP. How to remove data from a session?
As HTTP is state protocol.To maintain states on server and share data across multiple pages PHP session are used.PHP sessions are simple way to store data for individual users/client against a unique session ID.Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data,if session id is not present on server PHP creates a new session, and generate a new session ID.
Example Usage:-
1,'first_name'=>'php','last_name'=>'scots','status'=>'active']; //checking session if(isset($_SESSION['user_info'])){ echo "logged In"; } //un setting remove a value from session unset($_SESSION['user_info']['first_name']); // destroying complete session session_destroy(); ?>- How to register a variable in PHP session ?
In PHP 5.3 or below we can register a variable session_register() function.It is deprecated now and we can set directly a value in $_SESSION Global.
Example usage:
Also Read Laravel interview questions
- Where sessions stored in PHP ?
PHP sessions are stored on server generally in text files in a temp directory of server.
That file is not accessible from outside word. When we create a session PHP create a unique session id that is shared by client by creating cookie on clients browser.That session id is sent by client browser to server each time when a request is made and session is identified.
The default session name is “PHPSESSID”.
- What is default session time and path in PHP. How to change it ?
Default session time in PHP is 1440 seconds (24 minutes) and Default session storage path is temporary folder/tmp on server.
You can change default session time by using below code
- What are PHP Magic Methods/Functions. List them.
In PHP all functions starting with __ names are magical functions/methods. Magical methods always lives in a PHP class.The definition of magical function are defined by programmer itself.
Here are list of magic functions available in PHP
__construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone() and __debugInfo() .
- What is difference between include,require,include_once and require_once() ?
Include :-Include is used to include files more than once in single PHP script.You can include a file as many times you want.
Syntax:- include(“file_name.php”);
Include Once:-Include once include a file only one time in php script.Second attempt to include is ignored.
Syntax:- include_once(“file_name.php”);
Require:-Require is also used to include files more than once in single PHP script.Require generates a Fatal error and halts the script execution,if file is not found on specified location or path.You can require a file as many time you want in a single script.
Syntax:- require(“file_name.php”);
Require Once :-Require once include a file only one time in php script.Second attempt to include is ignored. Require Once also generates a Fatal error and halts the script execution ,if file is not found on specified location or path.
Syntax:- require_once(“file_name.php”);
- What are constructor and destructor in PHP ?
PHP constructor and a destructor are special type functions which are automatically called when a PHP class object is created and destroyed.
Generally Constructor are used to intializes the private variables for class and Destructors to free the resources created /used by class .
Here is sample class with constructor and destructer in PHP.
name = $name; } public function setLink(Foo $link){ $this->link = $link; } public function __destruct() { echo 'Destroying: ', $this->name, PHP_EOL; } } ?>Read More PHP INTERVIEW QUESTIONS