Top 100+ php Interview questions and answers @ Freshers, Experienced: here are top 100 + PHP interview questions with answers prepared by industry experts.If you’re searching for PHP Interview Questions for Experienced and Freshers here is the right place. There is a lot of opportunities from many reputed companies in the world. from the latest research, we found that php has a market share of about 52%.
So still, You have an opportunity to move ahead in your career in php development. webdev codex offers Advanced php Interview Questions 2018 that helps you in cracking your interview & fulfil dream career as a php web developer.
We have taken full attention to providing correct answers. download php Interview questions and answers. We are collecting all the official information from php.net.
Top 100+ php Interview questions and answers @ Freshers, Experienced
PHP Interview Questions
Q. Which is the latest version of PHP?
The latest stable version of PHP is 7.1.16 released at 29 Mar 2018.
Q. Define PHP?
PHP is an open source server side scripting language and used to develop dynamic websites. PHP stands for Hypertext Preprocessor, also called as Personal Home Page. It was created by Rasmus Lerdorf in 1995. so he is called as father of php. It is a free open source software released under the PHP license.
Q. What is the difference between $message and $$message?
$message is used to store variable data whereas $$message can be used to store a variable of a variable. Data stored in $message is fixed while data stored in $$message can be changed dynamically.
echo $message //Output:- you
echo $$message //output :-Me
Q. What is difference between echo() and print()?
echo() and print() both are functions used to show the output. but in echo we can take one or more parameters.
print() has a return value of true or false whereas echo has a void return type.
echo() is slightly faster than print.
Urldecode can be used to decode a string. Decodes any %## encoding in the given string (Inserted by urlencode)
Q. What is a difference between unset and unlink?
Unset is used to delete(destroy) a variable whereas unlink used to delete a file.
Q. what is the main difference between require and include, include_once?
The main difference is that when using require, it will throw a fatal error when a file is not found, whereas include and include_once will show a warning and continue to load the page.
Q. How do you register the variables into a session?
Ans: To register variables in a session, you need to use the session_register() function
- Cookies are stored in browser as text file format.
- It is stored limit amount of data. It is only allowing 4kb[4096bytes]
- It is not holding the multiple variable in cookies.
- We can accessing the cookies values in easily. So it is less secure.
- The setcookie() function must appear BEFORE the tag.
- If we Closing the browsers at the time.
- Setting the cookie time to expire the cookie.
- Sessions are stored in server side.
- It is stored an unlimited amount of data.
- It is holding the multiple variables in sessions.
Destroy Sessions :
- Using unset() session, we will destroy the sessions.
- Using session_destory(), we will destroy the sessions.
Q. Can you increase the execution time of a php script?
Ans: Yes, we can increase the execution time by changing a max_execution_time variable to desired time that you needed for executing a php script from php.ini file.
Q. What is nl2br() ?
nl2br() is a function that inserts a HTML line breaks before each newline in a string.
For example, nl2br(“i love php”) will return strings added with an HTML line breaks before all newlines in a string, and the output will be like:
Q. What are the types of errors in PHP and explain each one of them ?
The types of errors in PHP are Notices, Warnings & Fatal Errors.
- Notices are less important errors that you don’t want to give much importance to it. Like errors that occur, when you try to access a variable that is not defined. If you change the notice errors to be not displayed, you won’t see these kinds of errors at all.
- Warnings are errors of some serious nature that demand your attention. Even though these errors are displayed to the user, the script will not terminated. Example of this error includes accessing a file that doesn’t exist.
- Fatal Errors are mission critical errors that result in immediate termination of your script. Examples of these errors include, calling an object of a non-existent class etc.Q.
Q. What php image functions do you use to get the properties of an image?
these are various php image functions used to get image properties.
- exif_imagetype() – To get the type of the image
- getimagesize() – To get the size of the image
- imagesx() – To get the width of the image
- imagesy() – To get the height of the image
Q. What is use of var_dump ?
var_dump() is a function to use display the structured information like a type & value about one or more variable.
syntax : var_dump(variable1,variable2,…..variable n);
Q. What is str_replace()?
This function replace some characters with some other characters in a string , this function is case sensitive.
echo str_replace(“wordpress”,”php”,”hello wordpress”);
output:- hello php
Q. What is a .htacces file?
.htaccess is a configuration file running on Apache server.These .htaccess file used to change the functionality and features of apache web server .
- .htaccess file used for url rewrite
- .htaccess file used to make the site password protected.
- .htaccess file can restrict some ip addresses, so that on restricted ip adresses site will not open.
Q. What is type hinting in PHP?
Type Hinting is a PHP mechanism to allow developers to specify the type of function arguments and return. From PHP5,You can add type for function and method parameters which can be used as a Type Hint.
Q. How to read the contents of a file in PHP ?
This function is used to read the contents of a file into a string format.