Home > Interview Question and
Answer > PHP
PHP Interview Question and Answer
Interview questions and Answers for PHP. PHP Interview Questions for beginners and
professionals.
Interview question and answers for PHP. PHP Interview Qusetions for Session, PHP
Errors, Array, Variable, Functions, Include, File Handling, Upload and Download,
Database Connection, Read Records, DML Operation, MySQL. PHP Interview Questions
for beginners and professionals.
PHP Interview Question and Answers
1. What is PHP?
PHP - Hypertext Preprocessor is open source server side scripting language that
is widely used for creation of dynamic web applications. It supports MySQL database
and other DBMS and Other RDBMS includes Oracle, SQL Server, Sybase, PostgreSQL,
etc.
2. How to store value in PHP session ?
We can set or get a value by using $_SESSION Global.
3. What is default session time out and how to change it ?
Default session time in PHP is 24 minutes and default session storage path is temporary
folder/tmp on server. Alos by set value session.gc_maxlifetime from code.
4. What is difference between strstr() and stristr()
In PHP both functions are used to find the first occurrence of substring in a string
except stristr() is case-insensitive and strstr is case-sensitive,if no match is
found then FALSE will be returned.
5. What are the main error types in PHP ?
- Notices – Simple, non-critical errors that are occurred during the script execution.
An example of a Notice would be accessing an undefined variable.
- Warnings – more important errors than Notices, however the scripts continue the
execution. An example would be include() a file that does not exist.
- Fatal – this type of error causes a termination of the script execution when it
occurs. An example of a Fatal error would be accessing a property of a non-existent
object or require() a non-existent file.
6. What is "echo" in PHP?
PHP echo output one or more string. It is a language construct not a function. So
use of parentheses is not required. But if you want to pass more than one parameter
to echo, use of parentheses is required.
7. What is "print" in PHP?
PHP print output a string. It is a language construct not a function. So use of
parentheses is not required with the argument list. Unlike echo, it always returns
1.
8. What are the different loops in PHP?
For, while, do-while and for each.
9. What are different types of Print Functions available in PHP?
- print() Function
- echo() Function
- printf() Function
- sprintf() Function
- Var_dump() Function
- print_r() Function
10. What is the difference between GET and POST?
- GET displays the submitted data as part of the URL, during POST this information
is not shown as it’s encoded in the request.
- GET can handle a maximum of 2048 characters, POST has no such restrictions.
- GET allows only ASCII data, POST has no restrictions, binary data are also allowed.
- Normally GET is used to retrieve data while POST to insert and update.
11. What does isset() function?
The isset() function checks if the variable is defined and not null.
12. What is the use of count() function in PHP?
The PHP count() function is used to count total elements in the array, or something
an object.
13. How to get the length of string?
The strlen() function is used to get the length of string.
14. How can you submit a form without a submit button?
You can use JavaScript submit() function to submit the form without explicitly clicking
any submit button
15. What are the ways to include file in PHP?
PHP allows you to include file so that page content can be reused again. There are
two ways to include file in PHP.
include
require
Require and include both are used to include a file, but if file is not found include
sends warning whereas require sends Fatal error.
16. What is the difference between session and cookie?
The main difference between session and cookie is that cookies are stored on user's
computer in the text file format while sessions are stored on the server side. Cookies
can't hold multiple variables on the other hand Session can hold multiple variables.
You can manually set an expiry for a cookie, while session only remains active as
long as browser is open.
17. How to read a file in PHP?
PHP provides fread(), fgets(), fgetc() functions to read data from file. These functions
allow you to read all file data, read data line by line and read data character
by character.
18. How to create database connection in PHP?
The mysqli_connect() function is used to create connection in PHP.
19. How can we increase execution time of a PHP script?
By default, maximum execution time for PHP scripts is set to 30 seconds. If a script
takes more than 30 seconds, PHP stops the script and returns an error. You can change
the script run time by changing the max_execution_time directive in php.ini file.
20. 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 .
Home > Interview Question and
Answer > PHP