10 PHP Interview Questions You should know

Spread the love

Hello Programmers,

How are you doing? In this blog, I will discuss 10 PHP interview questions. I hope you will enjoy this blog.

#Question 1

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.
#Question 2

What are Traits?

Traits are a mechanism that allows you to create reusable code in languages like PHP where multiple inheritance is not supported. A Trait cannot be instantiated on its own.

It’s important that a developer knows the powerful features of the language (s)he is working on, and Trait is one of such features.

#Question 3

Can you extend a Final defined class?

No, you cannot extend a Final defined class. A Final class or method declaration prevents child class or method overriding.

#Question 4

Why we use final keyword?

A Final class or method declaration prevents child class or method overriding.

#Question 5

What are the __construct() and __destruct() methods in a PHP class?

All objects in PHP have Constructor and Destructor methods built-in. The Constructor method is called immediately after a new instance of the class is being created, and it’s used to initialize class properties. The Destructor method takes no parameters.

#Question 6

How we can get the number of elements in an array?

The count() function is used to return the number of elements in an array.

<?php echo count(YOUR_ARRAY); ?>

#Question 7

How would you declare a function that receives one parameter name hello?

If hello is true, then the function must print hello, but if the function doesn’t receive hello or hello is false the function must print bye.

function displayMessage($hello=false){
  echo ($hello)?'hello':'bye';
#Question 7

The value of the variable input is a string 1,2,3,4,5,6,7. How would you get the sum of the integers contained inside input?

<?= array_sum(explode(',',$input));?>
#Question 8

What’s the difference between the include() and require() functions?

They both include a specific file but on require the process exits with a fatal error if the file can’t be included, while include statement may still pass and jump to the next step in the execution.

#Question 9

How can we get the IP address of the client?

<?php $_SERVER["REMOTE_ADDR"]; ?>

#Question 10

What’s the difference between unset() and unlink()?

unset() sets a variable to “undefined” while unlink() deletes a file we pass to it from the file system.

Spread the love

About Anisur Rahman Shahin

Hello. My name is Shahin. I'm a tech enthusiast guy. Personally, I’m Optimistic and always in hurry kinda person. I'm a freelance web developer. I am working at Bangla Kings Software as Junior Laravel Developer. My Portfolio website: https://devshahin.com/

View all posts by Anisur Rahman Shahin →

5 Comments on “10 PHP Interview Questions You should know”

Leave a Reply

Your email address will not be published. Required fields are marked *