logo
Product
Product Tour
Aptitude Tests Coding Tests Psychometric Tests Personality Tests
Campus Hiring Features Proctoring Enterprise
Test Library Questions Pricing
Resources
Blog Case studies Books Tools
About us
Login
Log In

Search test library by skills or roles
⌘ K
logo
Assessment Platform Aptitude Tests Coding Tests Psychometric Tests Personality Tests

TRY FOR FREE

PHP Interview Questions
  1. What is NULL?
  2. How do you define a constant in PHP?
  3. What are break and continue statements?
  4. How would you compare objects in PHP?
  5. Explain constructor and destructor in PHP.
  6. What are include() and require() functions?
  7. What are PHP parameterized functions?
  8. What is an array?
  9. What are indexed array?
  10. What are associative array?
  11. What is htaccess?
  12. What is Persistent Cookie?
  13. What are Traits?
  14. What is PEAR in php?
  15. What are explode() and implode() functions?
  16. What are type casting and type juggling?
  17. What are substr() and strstr()?
  18. What is garbage collection?
  19. What is URL rewriting?
  20. What is PDO?
  21. What is Multidimensional array?
Advanced PHP Interview Questions
  1. What is a session?
  2. What are cookies in PHP?
  3. What is overloading and overriding in PHP?
  4. What are GET and POST in PHP?
  5. What is a lambda function?
  6. What are PHP Magic Methods?
  7. What is Type hinting?
  8. What is run time exception?
  9. Is multiple inheritance supported in PHP?
  10. How can you pass a variable by reference?
  11. What is the scope of a variable?
  12. What are magic constants in PHP?


Interview Questions

PHP Interview Questions and Answers (2023)

In this post, we put together the top PHP interview questions and answers for beginner, intermediate and experienced candidates. These most important questions are categorized for quick browsing before the interview or to act as a detailed guide on different topics in PHP interviewers look for.

PHP Online Test

PHP Interview Questions

What is NULL?

View answer

Hide answer

Null is a special data type which can have only one value: NULL. A variable of data type NULL is a variable that has no value assigned to it.

How do you define a constant in PHP?

View answer

Hide answer

A constant is an identifier (name) for a simple value. The value cannot be changed during the script.

A valid constant name starts with a letter or underscore (no $ sign before the constant name).

What are break and continue statements?

View answer

Hide answer

The break statement can also be used to jump out of a loop.

The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.

How would you compare objects in PHP?

View answer

Hide answer

To compare objects in PHP, you can use either the comparison operator (==) or identity operator (===).

Explain constructor and destructor in PHP.

View answer

Hide answer

In object oriented programming terminology, constructor is a method defined inside a class is called automatically at the time of creation of object. Purpose of a constructor method is to initialize the object. In PHP, a method of special name __construct acts as a constructor.

A destructor is called when the object is destructed or the script is stopped or exited. If you create a __destruct() function, PHP will automatically call this function at the end of the script.

What are include() and require() functions?

View answer

Hide answer

The Include() function is used to put data of one PHP file into another PHP file. If errors occur then the include() function produces a warning but does not stop the execution of the script i.e. the script will continue to execute.

The Require() function is also used to put data of one PHP file to another PHP file. If there are any errors then the require() function produces a warning and a fatal error and stops the execution of the script i.e. the script will continue to execute.

What are PHP parameterized functions?

View answer

Hide answer

PHP Parameterized functions are a piece of code that can be used repeatedly in a PHP program. Any number of parameters can be passed inside a parameterized function after the name of the function, inside the parentheses.

What is an array?

View answer

Hide answer

An array is a data structure that stores one or more similar type of values in a single value.

What are indexed array?

View answer

Hide answer

PHP indexed array is an array which is represented by an index number by default. All elements of array are represented by an index number which starts from 0. PHP indexed array can store numbers, strings or any object.

What are associative array?

View answer

Hide answer

Associative array refers to an array with strings as an index. Rather than storing element values in a strict linear index order, this stores them in combination with key values.

What is htaccess?

View answer

Hide answer

The .htaccess (Hypertext Access) file is an Apache distributed server configuration file. One can use the .htaccess file to set server configurations for a specific directory. This directory can be the root directory of the website or another subdirectory where the .htaccess file is created in order to enable extra features for that subdirectory.

What is Persistent Cookie?

View answer

Hide answer

A persistent cookie is a cookie that is stored in a cookie file permanently on the browser's computer. Temporary cookies are stored only in the browser's memory.

What are Traits?

View answer

Hide answer

Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

What is PEAR in php?

View answer

Hide answer

PEAR (PHP Extension and Application Repository) is a framework and distribution system for reusable PHP components.

What are explode() and implode() functions?

View answer

Hide answer

The implode() function takes an array, joins it with the given string, and returns the joined string. The explode() function takes a string, splits it by specified string, and returns an array.

What are type casting and type juggling?

View answer

Hide answer

PHP type casting allows you to convert a value from one type to another. Use a type casting operator to cast a value to the desired type.

Type juggling means dealing with a variable type. In PHP a variable type is the context in which it is used.

What are substr() and strstr()?

View answer

Hide answer

The substr() is a built-in function of PHP, which is used to extract a part of a string. The substr() function returns a part of a string specified by the start and length parameter.

The strstr() function searches for the first occurrence of a string inside another string. Note: This function is binary-safe.

What is garbage collection?

View answer

Hide answer

The garbage collector is triggered whenever 10,000 possible cyclic objects or arrays are currently in memory, and one of them falls out of scope.

The collector is enabled by default in every request.

What is URL rewriting?

View answer

Hide answer

URL rewriting is a technique that allows you to use a URL that actually goes to another URL within the same website. This is used mostly in dynamic database generated websites so the final URL is more Search Engine friendly.

What is PDO?

View answer

Hide answer

PDO in PHP (PHP Data Objects) is a lightweight, consistent framework for accessing databases in PHP. Database-specific features may be exposed as standard extension functions by any database driver that implements the PDO interface.

What is Multidimensional array?

View answer

Hide answer

A multidimensional array is an array containing one or more arrays. PHP supports multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep can be difficult to manage.

Advanced PHP Interview Questions

What is a session?

View answer

Hide answer

A PHP session is used to store data on a server rather than the computer of the user. Session identifiers or SID is a unique number which is used to identify every user in a session based environment.

What are cookies in PHP?

View answer

Hide answer

A cookie in PHP is a small file with a maximum size of 4KB that the web server stores on the client computer. They are typically used to keep track of information such as a username that the site can retrieve to personalize the page when the user visits the website next time.

What is overloading and overriding in PHP?

View answer

Hide answer

Method overloading occurs when two or more methods with same method name but different number of parameters in single class. PHP does not support method overloading. Method overriding means two methods with same method name and same number of parameters in two different classes means parent class and child class.

What are GET and POST in PHP?

View answer

Hide answer

Get and Post methods are the HTTP request methods used inside the

tag to send form data to the server. HTTP protocol enables the communication between the client and the server where a browser can be the client, and an application running on a computer system that hosts your website can be the server.

What is a lambda function?

View answer

Hide answer

A Lambda function is an anonymous PHP function that can be stored in a variable and passed as an argument to other functions/methods.

What are PHP Magic Methods?

View answer

Hide answer

Magic methods are special methods which override PHP's default's action when certain actions are performed on an object. All methods names starting with __ are reserved by PHP. Therefore, it is not recommended to use such method names unless overriding PHP's behavior.

What is Type hinting?

View answer

Hide answer

With Type hinting we can specify the expected data type (arrays, objects, interface, etc.) for an argument in a function declaration.

What is run time exception?

View answer

Hide answer

A RuntimeException is an exception that might also occur in code that is written and configured 'perfectly'. Such an exception may be caused by input from the end user, or an error in (the communication with) an external system. When a RuntimeException is thrown, it should not require a fix in the code.

Is multiple inheritance supported in PHP?

View answer

Hide answer

PHP doesn’t support multiple inheritance but by using Interfaces in PHP or using Traits in PHP instead of classes, we can implement it.

How can you pass a variable by reference?

View answer

Hide answer

When variables are passed by reference, use & (ampersand) symbol need to be added before variable argument. For e.g. : function( &$x ).

Scope of both global and function variable becomes global as both variables are defined by same reference.

What is the scope of a variable?

View answer

Hide answer

The scope of a variable is the part of the script where the variable can be referenced/used.

What are magic constants in PHP?

View answer

Hide answer

Magic constants are the predefined constants in PHP which get changed on the basis of their use. They start with double underscore (__) and ends with double underscore.

Other Interview Questions

ReactJS

Business Analyst

Android

Javascript

Power BI Django .NET Core
Java 8 R PostgreSQL
Spring Boot Drupal TestNG
Check Other Interview Questions
Join 1200+ companies in 75+ countries.
Try the most candidate friendly skills assessment tool today.
GET STARTED FOR FREE
40 min tests.
No trick questions.
Accurate shortlisting.

[email protected]

Product
  • Product Tour
  • Pricing
  • Features
  • Integrations
Usecases
  • Aptitude Tests
  • Coding Tests
  • Psychometric Tests
  • Personality Tests
Helpful Content
  • 52 pre-employment tools compared
  • Compare Adaface
  • Compare Codility vs Adaface
  • Compare HackerRank vs Adaface
  • Compare Mettl vs Adaface
BOOKS & TOOLS
  • Guide to pre-employment tests
  • Check out all tools
Company
  • About Us
  • Join Us
  • Blog
Locations
  • Singapore (HQ)

    32 Carpenter Street, Singapore 059911

    Contact: +65 9447 0488

  • India

    WeWork Prestige Atlanta, 80 Feet Main Road, Koramangala 1A Block, Bengaluru, Karnataka, 560034

    Contact: +91 6305713227

© 2022 Adaface Pte. Ltd.
Terms Privacy Trust Guide

🌎 Pick your language

English Norsk Dansk Deutsche Nederlands Svenska Français Español Chinese (简体中文) Italiano Japanese (日本語) Polskie Português Russian (русский)
Search 500+ tests by skill or role name