Php technical Interview Questions
Technical PHP Interview Questions
What are the three classes of errors that can occur in PHP?
The three basic classes of errors are notices (non-critical), warnings (serious errors) and fatal
errors (critical errors).
What is the difference between characters \034 and \x34?
\034 is octal 34 and \x34 is hex 34.
How can we pass the variable through the navigation between the pages?
It is possible to pass the variables between the PHP pages using sessions, cookies or hidden form
fields.
Is it possible to extend the execution time of a PHP script?
The use of the set_time_limit(int seconds) enables us to extend the execution time of a PHP script.
The default limit is 30 seconds.
Is it possible to destroy a cookie?
Yes, it is possible by setting the cookie with a past expiration time.
What is the default session time in PHP?
The default session time in php is until the closing of the browser
Is it possible to use COM component in PHP?
Yes, it's possible to integrate (Distributed) Component Object Model components ((D)COM) in PHP
scripts which is provided as a framework.
Explain whether it is possible to share a single instance of a Memcache between multiple
PHP projects?
Yes, it is possible to share a single instance of Memcache between multiple projects. Memcache is
a memory store space, and you can run memcache on one or more servers. You can also configure
your client to speak to a particular set of instances. So, you can run two different Memcache
processes on the same host and yet they are completely independent. Unless, if you have
partitioned your data, then it becomes necessary to know from which instance to get the data
from or to put into.
PHP INTERVIEW QUESTIONS
4. What does PEAR stands for?
Answers :PEAR means “PHP Extension and Application Repository”. it extends PHP and provides a higher level of programming for web developers.
5. What is Open Source Software?
Answers :Software in which the source codes are freely used, modify, and shared by anyone are called Open Source Software. These can also be distributed under licenses that adhere with the Open Source Definition.
6. What is the difference between include(), include_once() and require_once()
Answers :The include() statement includes and evaluates a specified line i.e. it will include a file based in the given path. require() does the same thing expect upon failure it will generate a fatal error and halt the script whereas include() will just gives a warning and allow script to continue. require_once() will check if the file already has been included and if so it will not include the file again.
7. Differences between GET, POST and REQUEST methods ?
Answers :GET and POST are used to send information from client browser to web server. In case of GET the information is send via GET method in name/value pair and is URL encoded. The default GET has a limit of 512 PHP INTERVIEW QUESTIONS 2 characters. The POST method transfers the information via HTTP Headers. The POST method does not have any restriction in data size to be sent. POST is used for sending data securely and ASCII and binary type’s data. The $_REQUEST contains the content of both $_GET, $_POST and $_COOKIE.
8. What are the different errors in PHP?
Answers :There are 4 basically types of error. Parse Error – Commonly caused due to syntax mistakes in codes e.g. missing semicolon, mismatch brackets. Fatal Error – These are basically run time errors which are caused when you try to access what can’t be done. E.g. accessing a dead object, or trying to use a function that hasn’t been declared. Warning Error – These occurs when u try to include a file that is not present, or delete a file that is not on the server. This will not halt the script; it will give the notice and continue with the next line of the script. Notice Error – These errors occurs when u try to use a variable that hasn’t been declared, this will not halt the script, It will give the notice and continue with the next line of the script.
9. What is session and why do we use it?
Answers :Session is a super global variable that preserve data across subsequent pages. Session uniquely defines each user with a session ID, so it helps making customized web application where user tracking is needed.
10. What is cookie and why do we use it?
Answers : Cookie is a small piece of information stored in client browser. It is a technique used to identify a user using the information stored in their browser (if already visited that website) . Using PHP we can both set and get COOKIE.
11.How we know the total number of elements of Array?
Answers : There are two methods through which we can know the total number of elements: sizeof($array_var) count($array_var)
12.What is the difference between explode() and split() functions?
Answers : Split function splits string into array by regular expression. Explode splits a string into array by string.
13.How to strip whitespace (or other characters) from the beginning and end of a string ?
Answers : The trim() function removes whitespaces or other predefined characters from both sides of a string.
14.How to set a page as a home page in a php based site?
Answers : index.php is the default name of the home page in php based sites. 15.How to find the length of a string? Answers : strlen() function used to find the length of a string. 16.what is the use of isset() in php? Answers :This function is used to determine if a variable is set and is not NULL. 17.What is the use of "ksort" in php? Answers : It is used for sort an array by key in reverse order
18.How to delete a file from the system
Answers :Unlink() deletes the given file from the file system
19.What is PEAR in php?
Answers :PEAR(PHP Extension and Application Repository) is a framework and repository for reusable PHP components. PEAR is a code repository containing all kinds of php code snippets and libraries. PEAR also offers a command-line interface that can be used to automatically install "packages". $message vs. $$message in PHP. $message is a variable with a fixed name. $$message is a variable whose name is stored in $message. If $message contains "var", $$message is the same as $var.Echo vs. print statement. PHP INTERVIEW QUESTIONS 4 echo() and print() are language constructs in PHP, both are used to output strings. The speed of both statements is almost the same. echo() can take multiple expressions whereas print cannot take multiple expressions. Print return true or false based on success or failure whereas echo doesn't return true or false.
20.Explain how to submit form without a submit button.
Answers : We can achieve the above task by using JavaScript code linked to an event trigger of any form field and call the document.form.submit() function in JavaScript code.Explain the different types of errors in PHP. Notices, Warnings and Fatal errors are the types of errors in PHP Notices: Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior. Warnings: Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user. Fatal errors: Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.
21.What is the use of PEAR in php?
Answers :PEAR is known as PHP Extension and Application Repository. It provides structured library to the PHP users and also gives provision for package maintenance.
22.What is the difference between PHP and JavaScript?
Answers :The difference lies with the execution of the languages. PHP is server side scripting language, which means that it can’t interact directly with the user. Whereas, JavaScript is client side scripting language, that is used to interact directly with the user.
23.What is the difference between $message and $$message?
Answers :The main difference between $message and $$message is that former one is a simple variable and later is a reference variable. $message is a variable with a fixed name and it consists of a fixed value. $$messages contains the variable itself.
24. What is the use of "echo" in php?
Answers :It is used to print a data in the webpage, Example: , The following code print the text in the webpage
25. How to include a file to a php page?
Answers :We can include a file using "include() " or "require()" function with file path as its parameter.
26.What's the difference between include and require?
Answers :If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
27. require_once(), require(), include().What is difference between them?
Answers :require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.
28. Differences between GET and POST methods ?
Answers :We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method