Top 101 PHP Interview Questions

Q1. What is PHP?


Q2. Differentiate between variables and constants in PHP?


Q3. What is a session in PHP?


Q4. What does PEAR stands for?


Q5. What was the old name of PHP?


Q6. Is PHP a case-sensitive language?


Q7. Explain the difference between static and dynamic websites?


Q8. Explain the difference between PHP4 and PHP5?


Q9. How do you execute a PHP script from the command line?


Q10. What are the popular Content Management Systems (CMS) in PHP?


Q11. What are the different types of variables present in PHP?


Q12. How can we display the output directly to the browser?


Q13. What are the popular frameworks in PHP?


Q14. Is multiple inheritance supported in PHP?


Q15. What are the rules for naming a PHP variable?


Q16. What is the difference between “echo” and “print” in PHP?


Q17. What is the meaning of a final class and a final method?


Q18. What is "echo" in PHP?


Q19. What is "print" in PHP?


Q20. What is the purpose of @ in PHP?


Q21. What is the difference between $message and $$message?


Q22. How can PHP and HTML interact?


Q23. Explain the importance of Parser in PHP?


Q24. How can PHP and Javascript interact?


Q25. What is the use of the function ‘imagetypes()’?


Q26. What are the ways to define a constant in PHP?


Q27. What are the different types of Array in PHP?


Q28. What are magic constants in PHP?


Q29. What are the functions to be used to get the image’s properties (size, width, and height)?


Q30. Explain the different types of errors in PHP?


Q31. What are traits?


Q32. What are the different loops in PHP?


Q33. How failures in execution are handled with include() and require() functions?


Q34. What is the main difference between require() and require_once()?


Q35. What is the most used method for hashing passwords in PHP?


Q36. What is the use of count() function in PHP?


Q37. How is it possible to set an infinite execution time for PHP script?


Q38. What are cookies? How to create cookies in PHP?


Q39. What is the use of header() function in PHP?


Q40. What does the PHP error ‘Parse error in PHP – unexpected T_variable at line x’ means?


Q41. What is the difference between ASP.NET and PHP?


Q42. What is the function file_get_contents() useful for?


Q43. What does isset() function?


Q44. How can we connect to a MySQL database from a PHP script?


Q45. What is the use of session_start() and session_destroy() functions in PHP?


Q46. What is the array in PHP?


Q47. What is the function mysql_pconnect() useful for?


Q48. How be the result set of Mysql handled in PHP?


Q49. Explain some of the PHP array functions?


Q50. What is PDO in PHP?


Q51. Differentiate between GET and POST


Q52. How is it possible to know the number of rows returned in the result set?


Q53. How to get the length of string?


Q54. Explain type hinting in PHP?


Q55. Explain some of the PHP string functions?


Q56. What is the difference between mysqli_fetch_object() and mysqli_fetch_array()?


Q57. How to terminate the execution of a script in PHP?


Q58. How can you submit a form without a submit button?


Q59. How can we access the data sent through the URL with the GET method?


Q60. How can we access the data sent through the URL with the POST method?


Q61. What are the ways to include file in PHP?


Q62. How can we check the value of a given variable is a number?


Q63. How do I check if a given variable is empty?


Q64. What does the unlink() function mean?


Q65. What does the unset() function mean?


Q66. What is the method to register a variable into a session?


Q67. Write syntax to open a file in PHP?


Q68. How is it possible to remove escape characters from a string?


Q69. How do I escape data before storing it in the database?


Q70. Is it possible to remove the HTML tags from data?


Q71. How can we define a variable accessible in functions of a PHP script?


Q72. How to write in a file in PHP?


Q73. How to delete file in PHP?


Q74. How is it possible to return a value from a function?


Q75. How to upload file in PHP?


Q76. How can you pass a variable by reference?


Q77. How is the ternary conditional operator used in PHP?


Q78. How to download file in PHP?


Q79. How can you send email in PHP?


Q80. What is the function func_num_args() used for?


Q81. What is htaccess in PHP?


Q82. Explain PHP explode() function?


Q83. Explain PHP split() function?


Q84. If the variable $var1 is set to 10 and the $var2 is set to the character var1, what’s the value of $$var2?


Q85. How can we get IP address of a client in PHP?


Q86. What is the meaning of a Persistent Cookie?


Q87. What does accessing a class via :: means?


Q88. In PHP, objects are they passed by value or by reference?


Q89. What are the data types in PHP?


Q90. What’s the difference between __sleep and __wakeup?


Q91. What is faster?

$variable1 = 'Hello ';
$variable2 = 'World';
$variable3 = $variable1.$variable2;
============ Or ============
$variable3 = "$variable1$variable2";

Q92. How to concatenate two strings in PHP?


Q93. What is the difference between session_unregister() and session_unset()?


Q94. What does $GLOBALS mean?


Q95. What is a lambda function in PHP?


Q96. What does $_SERVER mean?


Q97. What does $_FILES means?


Q98. How can we get the error when there is a problem to upload a file?


Q99. How can we change the maximum size of the files to be uploaded?


Q100. What is the difference between Exception::getMessage and Exception:: getLine?


Q101. How can we determine whether a variable is set?