Home Interview Questions Core PHP Interview Questions & Answers for Freshers and Experienced

Core PHP Interview Questions & Answers for Freshers and Experienced

PHP Interview Questions and Answers

Here in this article, we will talk about probably the most widely recognized and as often as possible asked Core PHP interview questions & answers.

The interest for PHP employments is expanding step by step. Individuals who are scanning or planning for PHP occupations, need to confront some basic questions in the interview.

Along these lines, in the event that you are a fresher and on the off chance that you wish to make your career as a PHP developer or even an accomplished proficient hoping to verify a higher position, at that point you should peruse this article to secure your opportunity to find a PHP line of work effectively and rapidly.

Core PHP Interview Questions

1. What is PHP?

PHP is one of the famous server-side scripting languages for building up a web application.

The full form of PHP is Hypertext Preprocessor. It is utilized by implanting HTML for making dynamic substance, speaking with a database server, taking care of session and so forth.

2. Why do we use PHP?

There are a few advantages to utilizing PHP. First, of all, it is thoroughly allowed to utilize. So anybody can use PHP with no expense and host the site at a negligible expense.

It underpins different databases. The most usually utilized database is MySQL which is additionally allowed to utilize. Numerous PHP structures are utilized now for web advancement, for example, CodeIgniter, CakePHP, Laravel and so on.

These structures make the web advancement task a lot simpler than previously.

3. Is PHP a strongly typed language?

No. PHP is a weakly composed or inexactly composed language.

Which means PHP does not require to announce information kinds of the variable when you proclaim any factor like the other standard programming dialects C# or Java. When you store any string an incentive in a variable then the information type is the string and in the event that you store a numeric incentive in that equivalent variable, at that point the information type is an Integer.

4. What are namespaces in PHP?

PHP Namespaces is used for grouping related classes, interfaces, functions and constants.

# define namespace and class in the namespace
namespace Modules\Admin\;
class CityController {
# include the class using namespace
use Modules\Admin\CityController ;

5. How to add 301 redirects in PHP?

To add 301 redirect in PHP use below code snippet in your file.

header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: /option-a”);

6. What is the difference between unset and unlink?

Unlink: It is used to remove a file from the server.
usage:unlink(‘path to file’);

Unset: This function is used for variable management
usage: unset($var);

7. What is Pear in PHP?

PEAR (Php Extension and Application Repository) is a repository of PHP software code. It provides:

An organized library of open-source code for PHP clients
A framework for code dispersion and bundle support
A standard style for code written in PHP
The PHP Extension Community Library (PECL)
A site, mailing records, and download mirrors to help the PHP/PEAR people group

8. Explain Type hinting in PHP?

Type Hinting in PHP is a component to enable developers to indicate the kind of function arguments and return. From PHP5, You can include type for function and technique parameters which can be utilized as a Type Hint.

The meaning of the Type Hinting determines the parameter type when you consider the function. If the argument type and the predetermined kind does not coordinate, PHP will create a fatal error. In short, It enables you to control the execution of how the sort of information goes to the capacity.

9. What is default session time and path in PHP? How to change it?

Default session time in PHP is 1440 seconds (24 minutes) and the Default session storage path is temporary folder/tmp on the server.

You can change default session time by using below code

// server should keep session data for AT LEAST 1 hour
ini_set(‘session.gc_maxlifetime’, 3600);

// each client should remember their session id for EXACTLY 1 hour


T_PAAMAYIM_NEKUDOTAYIM is the scope resolution operator. In most languages, it is the double-colon (::).

11. What is the difference between Method overriding and overloading in PHP?

Overloading is defining functions that have similar signatures, yet have different parameters. Overriding is only pertinent to derived classes, where the parent class has defined a method and the derived class wishes to override that method.

In PHP, you can only overload methods using the magic method __call.

An example of overriding:


class Foo {
function myFoo() {
return “Foo”;

class Bar extends Foo {
function myFoo() {
return “Bar”;

$foo = new Foo;
$bar = new Bar;
echo($foo->myFoo()); //”Foo”
echo($bar->myFoo()); //”Bar”

12. What is cURL in PHP?

cURL is a way you can hit a URL from your code to get an HTML reaction from it. It’s utilized for direction line cURL from the PHP language. cURL is a library that gives you a chance to make HTTP demands in PHP.

13. What is a composer in PHP?

Composer is an application-level bundle administrator for the PHP programming language that gives a standard arrangement to overseeing conditions of PHP programming and required libraries.

14. How can you get web browser’s details using PHP?
15. What is the difference between an interface and an abstract class?
16. Difference between array_combine and array_merge?
17. What is php.ini & .htacess file?
18. How to terminate the execution of a script in PHP ?
19. What is difference between md5 and SHA256?
20. What is the difference between nowdoc and heredoc?
21. What is a path Traversal ?
22. Write logic to print Floyd’s triangle in PHP?
23. What is Cross-site scripting?
24. What are the encryption functions available in PHP ?
25. What is purpose of @ in Php ?
26. What is difference between strstr() and stristr() in PHP?
27. What is list in PHP?
28. What is difference Between PHP 5 and 7?
29. What is difference between ksort() and usort() functions.
30. What should be the length of variable for SHA256?
31. What is MIME?
32. What are access specifiers?
33. What is difference between explode() or split() in PHP?
34. How can i execute PHP File using Command Line?
35. How to block direct directory access in PHP?
36. Explain preg_Match and preg_replace?
37. Explain mail function in PHP with syntax?
38. List few sensible functions in PHP?
39. How can you get the size of an image in PHP?
40. How can we convert the time zones using PHP?
41. How to access a Static Member of a Class in PHP?
42. What are differences between PECL and PEAR?
43. What is difference between session and cookie in PHP?
44. How to get length of an array in PHP?
45. Which Scripting Engine PHP uses?
46. What is the difference between runtime exception and compile time exception?
47. Code to open file download dialog in PHP?
48. Explain Traits in PHP?
49. How to get the IP address of the client/user in PHP?
50. How will you calculate days between two dates in PHP?
51. How to get no of arguments passed to a PHP Function?
52. How to Pass JSON Data in a URL using CURL in PHP ?
53. What is the difference between == and === operator in PHP ?
54. How to register a variable in PHP session ?
55. What is session in PHP. How to remove data from a session?
56. Code to upload a file in PHP ?
57. What is difference between strstr() and stristr() ?
58. What are constructor and destructor in PHP ?
59. What is PECL?
60. What is Gd PHP?
61. Is multiple inheritance supported in PHP ?
62. How is a constant defined in a PHP script?
63. What is the use of Mbstring?
64. How to get number of days between two given dates using PHP ?
65. What are the differences between GET and POST methods in form submitting, give the case where we can use get and we can use post methods?
66. What are PHP Magic Methods/Functions. List them.
67. Why should I store logs in a database rather than a file?
68. What are different types of Print Functions available in PHP?
69. How to access standard error stream in PHP?
70. Advantages and Application Areas of PHP
71. What are the difference between echo and print?
72. What is Mcrypt used for?
73. What are different types of errors available in Php ?
74. How to increase the execution time of a PHP script ?
75. List data types in PHP ?
76. What is difference between include,require,include_once and require_once() ?
77. Where sessions stored in PHP ?
78. How to remove duplicate values from a PHP Array?
79. How to check curl is enabled or not in PHP?
80. How to create a public static method in PHP?

Check Also

Spring Interview Questions & Answers Freshers and Experienced

Is it true that you are considering Spring Framework as your career after your vocation in…