Preparing for PHP Technical round is most stressful and time-consuming. To overcome from this stress, Coding Tag provide you the top PHP interviews questions that are frequently asked by recruiters of all the MNC Company. These questions are specifically, taken from important technical topics which will be very helpful for both freshers and experienced to crack technical round.
1. What does the initials of PHP Stands for?
PHP means PHP: Hypertext PreProcessor that previously stood for personal home pages.
2. Who is the father of PHP?
3. What is PHP and features of PHP?
PHP is an open source server-side scripting language which allows creating web pages dynamically and used for web applications and can be embedded into HTML code. To access PHP Scripts, only web browser is required by client computer. PHP can also be used in combination with various web content management systems, web template systems and web frameworks.
4. Which programming language does PHP resemble to?
PHP syntax bears resemblance with PERL and C.
5. What is genuinely used PHP version?
6. What is Open Source Software?
Open Source Software's are the software that are dispersed with source code, that can be freely used, read, modify and shared by anyone.
The Open Source Software (OSS) should meet the following bench marks:
Source code must be included with program and must be distributed freely.
Modified versions of source code may be redistributed.
Users must be able to modify that source code.
7. How can we submit a form without a submit button?
Java script submit() function can be used for submit form without submit button on click call document.formname.submit ().
8. How can we create a database using PHP and MySQL?
We must require a database before saving or accessing any data and to create any database in MySQL, CREATE DATABASE Statement is used.
e.g. mysql_create_db("Database Name")
9. How to include a file to a PHP page?
It is possible to include one PHP file's content to other PHP file. The two functions "include()" or "require()" with file path as its parameter can be used to include a file.
10. What is the use of "ksort" in PHP?
It is used for sorting an associative array key in ascending order.
$age=array("Jai"=>"59", "Dolly"=>"43", "Mack"=>"49", "Sam"=>"46");
foreach ($age as $a => $b)
echo "$a = $b\n";
11. How to get the value of current session id?
session_id() function can be used to return the session id.
12. What are the functions of header () function in PHP?
This function is used for sending raw HTTP header to a client, redirection of pages. It is very important to remark, that header () must be called before real output is seen, either by blank lines in a file, or from PHP or HTML tags.
13. Is multiple inheritances supported in PHP?
PHP includes only single inheritance. A Class can be extended from only one class and keyword used is 'extended'.
14. How can we execute a PHP script using command line?
We just need to run the PHP command line interface program and add the PHP Script file as the Command line argument
Following are the four steps and paths that can be used to execute PHP in command line.
1. First login to your windows system.
2. Press windows and R key of keyboard simultaneously to open command prompt.
3. To find PHP executable file, move across PHP directory.
4. Executable file are accessed and then Path to PHP File.
The path with Change directory command used is C:\wamp\bin\php\php5.3.13. For Wamp Webserver users: php.exe path-to-your-php-file. If you visualize php version info,you can use php path-to-your-php-file instead of that command.
15. How can PHP and HTML Interact?
It is possible to generate HTML through PHP scripts and it is possible to pass information's from HTML to PHP.
16. What are final method and a final class?
Final is introduced in PHP5. Final methods cannot be over-rided and final class cannot be extended.
17. What is the difference between PHP4 and PHP5?
Zend Engine II is used in PHP5.
The addslashes () function is used instead of Magic quotes.
The more procedure ordinate language is replaced with additional object oriented concepts in PHP5.
Abstract classes can be declared in PHP5.
Static methods and properties and exceptions are introduced in PHP5.
There are three level of visibility are present in PHP5 i.e. public protected and private.
In PHP4 all objects was passed by value but in PHP5 all objects are passed by reference and more reserved keywords are used in PHP5
18. How can we directly display output to the browser?
Special tags <? = and?> are used to display directly to browser.
19. How comparisons of objects are done in PHP5?
The operator '==' is used to test is two objects are instanced from the same class and equal values and same attributes. We can test if two objects are referring to the same instance of the same class by the use of the identity operator '==='.
20. What type of operations is needed when values are passes through an URL or a form?
We require them to encode and decode with two functions htmlspecialchars() and urlencode.
21. How the result sets of MySQL is handled in PHP?
These can be handled with the use of mysql_fetch_assoc, mysql_fetch_array, mysql_fetch_row or mysql_fetch_object.
22. What is the function mysql_pconnect() useful for?
mysql_pconnect() assure a continual connection to the database. It means that when PHP script ends, the connection do not close.
23. Explain the different errors occur in PHP?
There are mainly four types of error found in PHP
Fatal Error: Fatal errors are known as critical runtime errors. When we trying to access inaccessible data. When this error occurs; it results in immediate script termination.
e.g. trying to access the undeclared function and dead objects.
Parse Error: These types of errors are found when there are syntax faults in code. When this error occurs it stop scripts execution. E.g. if there are mismatch brackets or semicolon missing.
Warning Error: These errors will not stop script execution but give the warning and continue with further line of the script. Warning errors are due to the reason when we trying to include the missing files or when we try to use the wrong no of parameters in a function.
Notice Error: These errors resembles with warning errors i.e. execution does not halt script. It also gives the notice and continues with further line of the script.
25. What is the difference between $$name and $name?
$$name is a reference variable whereas $name is variable.
E.g. $name=kelvi and $$name=joy so $kelvi value is joy
26. What is PEAR in PHP?
PEAR stands for PHP extension and application repository is a framework consists of collections of PHP reusable components, libraries and codes snippets used to make life of developer simple, comfortable and secure. PEAR also provides a command line interface to automatically install packages.
27. What is the name of scripting engine in PHP?
28. What are the various methods used in form submission of PHP?
Two methods i.e. get and post
29. How can we get the browser properties using PHP?
We can use the following simple code to get the browser properties:
echo $_SERVER['HTTP_USER_AGENT'] . â\n\nâ;
$browser = get_browser();
30. What is a session in PHP?
A session is the alternate way to make stored information accessible across the multiplied pages. The function used to create a session is session_start(). A file is created in temporary directory by session on the server, which consists of variables and their values. This information will be making available to various pages on the site.
When we make any working environment, we open an application and do some modifications and after that terminate that application. This is more similar to session. Our computer knows all the logging information about you but when we are accessing internet, there one problem occur: web server does not have information. This problem is solved by session variables. Session helps to make customized web application where user tracking is required.
31. How we can destroy any session?
We can use the destroy function described in following syntax.
32. What is the difference between unset and unlink function?
When we want to destroy any variable, we can use the unset() function and when w want to destroy a file unlink() function is used.
33. How we can get the current session ID?
For this, we have to go session start and then go to echo session id
34. How we can differentiate between explode and split functions?
Both explode and split functions are used to split a string in array and the common difference is that explode uses a string and split uses a pattern.
Explode is faster then split because it does not do regular expression based matching, so regex parser is not required to analyze the string. Split() has been deprecated as of PHP5.3.0 and using of this split function is pessimistic.
35. What is use of PDO classes?
PDO stand for PHP Data Object. PDO contain collections of PHP extensions that provide database precise drivers and a core PDO classes. It also target data access abstraction. To be compatible with latest versions of PHP, the advanced oops feature is required. It grants a lightweight data-access abstraction layer persistent interface to access databases in PHP.
36. What is the use of count () function in php?
It is used to count the properties and elements of an object recursively
Where, array name specifies countable object and mode sets the function's mode.
37. During PHP installation which function creates a HTML page to display records of how PHP was installed?
38. What is the difference between print and echo in PHP?
Both print and echo are used to display output data on a screen and there are very minor differences are described below:
Print can be used in expressions and has a return value of 1 whereas echos has no return value. Print can take only one parameter whereas echo can take multiple. Print is slower than echo.
39. What is the difference between session and cookie?
|Session is more secure||Cookie is less secure because cookie values can easily accessed|
|Session is stored in server side||Cookie is secured on client's computer|
|Session can hold multiple variables||Multiple variable are not holded in cookies|
|We can store unlimited data||We can store data in limits|
|The session_start() function must be used before the html tag||The setcookie() function must be used before the html tag|
40. What is the purpose of php.ini file?
When we install and explore PHP, we will find one configuration file, where we can visualize, access and modify the functionality of PHP. This file is the current and final way to affect functionality of PHP in which, we can declare changes to PHP settings by editing the existing php.ini file. The php.ini file is read each time PHP is initialized.
We can create a new php.ini file in cPanel in the following steps:
1. First we have to login to cPanel.
2. Click on File manager icon in the Files category.
3. Click Go after selecting Home Directory.
4. On top of the page, click the new file button and enter php.ini in the new file name field.
5. Click the file named php.ini.
6. Select and click the edit button.
41. What is escaping to PHP?
To differentiate PHP code from other elements, the PHP parsing engine is required. This mechanism is known as escaping to PHP
42. Is it possible to create a class in PHP?
43. How will you retrieve source line with the use of exception class in PHP after error occurred?
Getline method() can be used to return source line.
44. PHP is a case sensitive language?
Yes, PHP is a case sensitive except user defined functions
45. What is the objective of getdate function?
To return the current time or date information or timestamp, the getdate() function is used.
Syntax used is getdate(timestamp);
Where, timestamp is optional and specifies an integer Unix timestamp.
46. Explain PHP variables?
Variables can be used to store data like numbers, string of text etc. Once a variable is declared it can be reused in all over the code and the assignment operator is used to assign the value to the variables.
$var_name = value;
Variable names used in PHP are case sensitive.
47. How to redirect a page in PHP?
48. What is the difference between post and get methods in php?
The browser client can send information to web server in two ways i.e. the GET method and POST method.
|POST Method||GET Method|
This method can transfer large amount of data.
Get method can send limited amount i.e.1024 bytes.
|More Secure.||Less Secure.|
POST is used for writing data.
GET is used for retrieving data.
Data is not visible to user.
Data is visible to user.
We can make bookmark by using POST.
We cannot make a bookmark.
In POST all data control travel through URL.
|All data travel through URL.|
49. Name PHP supported database?
There are many PHP supported databases available for e.g.
e) SQL server
50. What is the difference between include and require in PHP?
If we include a file which does not exists, it will simply throw an error and rest of the script will run.
|If we user require and that file does not exists than it will throw and error and halt the script from further execution|
If file is not much important to include than we should use so that script should continue when file is not found
If file is much important than we should use required so that it should stop to execute when file is not found