LearnThatStack Ace your next interview
Backend Development

PHP.

Start free Change topic Change
Practice · Questions

All questions

Showing of 82
Beginner 25
01

What is PHP and what does it stand for?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

PHP stands for PHP: Hypertext Preprocessor. It is a recursive acronym, because the first word of the name is the name itself. PHP is an open source server-side scripting language designed for web development.

The code runs on the server, and PHP sends the result to the browser, usually as HTML. The visitor receives only that output, never the PHP source. PHP can be embedded directly in HTML between <?php and ?> tags, or fill whole files.

PHP is also platform-independent, so the same code runs on Linux, Windows and macOS.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What are the differences between echo and print in PHP?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Both output data, but echo can take several comma-separated arguments and returns nothing, while print takes exactly one argument and always returns 1. Because it returns a value, print can sit inside an expression, such as an if condition.

echo "Hello", " World"; // Works
print "Hello World";     // Works
// print "Hello", " World"; // Error - multiple parameters not allowed

Neither is a real function. Both are language constructs, so parentheses are optional for both. echo("hello") works only because the parentheses belong to the expression being printed, which is also why echo("a", "b") is a parse error. As constructs, neither works as a variable function, where PHP calls the function whose name a variable holds.

echo is marginally faster because it returns no value, but the gap is too small to matter. The <?= tag is shorthand for <?php echo.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

Explain the difference between include, require, include_once, and require_once.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

include and require both load and run another file, but a missing file triggers a warning with include and stops the script with require. The _once versions behave the same way, except they skip a file already loaded.

  • include emits an E_WARNING for a missing file, and the script keeps running.
  • require throws an Error for a missing file, which ends the script unless caught. Before PHP 8.0 it raised a fatal E_COMPILE_ERROR.
  • include_once and require_once load a file only once. A later call for the same file returns true without loading it.

The _once variants prevent redeclaration errors when the same file might be included more than once, such as a shared helpers file. Use require_once for files the code cannot run without, and plain include for optional parts, such as a template fragment.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What are PHP tags and what are the different types?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

PHP tags mark where PHP code starts and stops, which is how PHP is embedded in HTML. The parser runs the code inside the tags and outputs everything else unchanged.

  • Standard tags <?php ... ?> always work and are the recommended choice.
  • Short echo tags <?= ... ?> print a value. They have always been available since PHP 5.4.
  • Short tags <? ... ?> need the short_open_tag setting, so avoid them.
  • ASP tags <% ... %> were removed in PHP 7.0.

In a file that contains only PHP, leave out the closing ?>, so no stray newline gets sent as output.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What are the main data types in PHP?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

PHP's data types fall into three groups: scalar types that hold one value, compound types that hold several, and special types.

  • Scalar: bool for true or false, int and float for numbers, and string for text. A float is also called a double.
  • Compound: array, object and callable. iterable is a type alias for an array or a Traversable object.
  • Special: null for no value, and resource for a handle such as a file.

PHP is dynamically typed. A variable takes its type from its value and can change type while the script runs. Type declarations add checks where you want them.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

Explain the difference between == and === operators.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

== checks loose equality, comparing values after type juggling, so PHP may convert one side first. === checks strict equality and is true only when the value and the type both match, with no conversion.

$a = "5";  // string
$b = 5;    // integer
var_dump($a == $b);  // true (values equal after conversion)
var_dump($a === $b); // false (different types)

Loose comparison causes surprises. Before PHP 8, 0 == "foo" was true, because PHP turned the string into the number 0. Since PHP 8, a number compared with a non-numeric string is compared as strings, so the result is false. Numeric strings still compare as numbers, so "1" == "01" is true.

Use === and !== by default, especially where 0, "" and null can appear. Reach for == only when the conversion is what you want.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

What is type juggling in PHP?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Type juggling is PHP converting a value to another type automatically, based on the context it is used in. An arithmetic operator needs numbers, so a numeric string becomes a number.

$str = "10";
$num = 5;
echo $str + $num; // 15 (string converted to integer)

It is convenient, but it can give unexpected results. Since PHP 8, a string that is not numeric at all, such as "abc", throws a TypeError in arithmetic. A string with a numeric start, such as "10 apples", still works but raises a warning.

To avoid surprises, use strict comparison with === and add type declarations to parameters and return values.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

What are superglobal variables in PHP?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Superglobals are built-in variables that are available in every scope, so a function can read them without the global keyword.

  • $_GET: query string parameters from the URL
  • $_POST: form data from a POST request body
  • $_COOKIE: cookies sent by the browser
  • $_FILES: uploaded files
  • $_SESSION: data in the current session
  • $_SERVER: headers, paths and server details
  • $_ENV: environment variables
  • $_REQUEST: $_GET, $_POST and $_COOKIE combined by default
  • $GLOBALS: every global variable

Values in $_GET, $_POST and $_COOKIE come from the client, so treat them as untrusted. Prefer them over $_REQUEST, so you know where each value came from.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

09

How do you declare constants in PHP and what's the difference between define() and const?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Declare a constant with the const keyword or the define() function. The main difference is timing. const is defined at compile time, so it must sit at the top level of a file or inside a class. define() runs at runtime like any function call, so it works anywhere, including inside an if.

define('MAX_SIZE', 100);
const MIN_SIZE = 10;

// define() can be conditional
if ($condition) {
    define('DYNAMIC', 'value');
}
// const cannot be used conditionally

Because of that, const cannot appear inside functions, loops or if and try blocks. define() can also build the constant's name at runtime and accepts any expression as the value. Only const can declare class constants.

Prefer const for fixed values, and keep define() for constants that are conditional or have computed names.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

10

What is the null coalescing operator and how does it work?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

The null coalescing operator ?? returns its left operand if it exists and is not null, and otherwise returns the right operand. PHP 7.0 added it as a short form of a ternary with isset(). It is handy for default values.

$username = $_GET['user'] ?? 'guest';
// Equivalent to:
$username = isset($_GET['user']) ? $_GET['user'] : 'guest';

Like isset(), it raises no warning when the key or variable is missing. It can be chained, so $_GET['user'] ?? $_POST['user'] ?? 'guest' returns the first value that is set.

PHP 7.4 added the null coalescing assignment operator ??=. It assigns only when the left side is missing or null, as in $config['timeout'] ??= 30.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

11

Explain the spaceship operator in PHP.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

The spaceship operator <=> is a three-way comparison operator. It returns -1 when the left side is smaller, 0 when both sides are equal, and 1 when the left side is greater. PHP 7.0 introduced it.

echo 1 <=> 2;  // -1
echo 2 <=> 2;  // 0
echo 3 <=> 2;  // 1

It follows PHP's usual comparison rules, so it works on numbers, strings and arrays. Its main use is sorting callbacks, because usort() expects exactly this kind of result. For example, usort($users, fn($a, $b) => $a->age <=> $b->age) sorts users by age.

It also compares several values at once. Comparing arrays, as in [$a->last, $a->first] <=> [$b->last, $b->first], sorts by last name and then by first name. Swap $a and $b to sort in descending order.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

12

What is the difference between break and continue statements?

Part of Pro
13

What are variable functions in PHP?

Part of Pro
14

Explain the difference between pass by value and pass by reference.

Part of Pro Visual
15

What are anonymous functions (closures) in PHP?

Part of Pro Visual
16

What is the difference between func_get_args() and using parameters?

Part of Pro
17

Explain variable scope in PHP.

Part of Pro Visual
18

What is method chaining and how do you implement it?

Part of Pro
19

Explain the difference between array_merge() and array_combine().

Part of Pro Visual
20

What are the different error levels in PHP?

Part of Pro
21

What is the difference between single-quoted and double-quoted strings in PHP?

Part of Pro
22

What is the difference between GET and POST requests in PHP?

Part of Pro
23

What are the main principles of OOP in PHP?

Part of Pro
24

What's the difference between indexed and associative arrays?

Part of Pro
25

How do you check if a key exists in an array?

Part of Pro
Intermediate 50
26

Explain the difference between abstract classes and interfaces.

Part of Pro
27

What are PHP traits and when would you use them?

Part of Pro
28

What are magic methods in PHP?

Part of Pro
29

Explain late static binding in PHP.

Part of Pro Visual
30

What are PHP namespaces and why are they important?

Part of Pro Visual
31

What are the differences between array_map(), array_filter(), and array_reduce()?

Part of Pro
32

Explain the difference between errors and exceptions in PHP.

Part of Pro Visual
33

How do you create and handle custom exceptions?

Part of Pro
34

What is the finally block and when is it executed?

Part of Pro
35

What is PDO and what are its advantages over MySQLi?

Part of Pro
36

What are prepared statements and why are they important?

Part of Pro
37

Explain database transactions in PHP.

Part of Pro
38

What is the N+1 query problem and how do you solve it?

Part of Pro Visual
39

What's the difference between sessions and cookies?

Part of Pro Visual
40

How do you implement secure session management?

Part of Pro
41

What is session fixation and how do you prevent it?

Part of Pro Visual
42

What is SQL injection and how do you prevent it?

Part of Pro Visual
43

Explain Cross-Site Scripting (XSS) and prevention methods.

Part of Pro
44

What is CSRF and how do you protect against it?

Part of Pro Visual
45

How do you properly hash passwords in PHP?

Part of Pro Visual
46

What are the security implications of file uploads?

Part of Pro
47

What are the differences between REST and SOAP?

Part of Pro
48

How do you handle API authentication in PHP?

Part of Pro
49

What is CORS and how do you handle it in PHP?

Part of Pro Visual
50

How do you implement rate limiting in PHP APIs?

Part of Pro Visual
51

What are PHP CodeSniffer and PHP CS Fixer?

Part of Pro
52

What is Composer and how does it work?

Part of Pro
53

Explain PSR standards and their importance.

Part of Pro
54

What is the difference between require and autoloading?

Part of Pro Visual
55

How does PHP handle memory management?

Part of Pro Visual
56

What does declare(strict_types=1) change, and where does it apply?

Part of Pro Visual
57

What is opcode caching and how does it improve performance?

Part of Pro
58

Explain lazy loading and eager loading in the context of PHP.

Part of Pro Visual
59

What are typed properties in PHP and their benefits?

Part of Pro
60

Explain union types in PHP 8.

Part of Pro
61

What are attributes (annotations) in PHP 8?

Part of Pro
62

What is the match expression and how does it differ from switch?

Part of Pro
63

Explain constructor property promotion in PHP 8.

Part of Pro
64

What are enumerations (enums) in PHP?

Part of Pro
65

Explain the Singleton pattern and its implementation in PHP.

Part of Pro
66

What is dependency injection and why is it important?

Part of Pro
67

Explain the MVC pattern in PHP applications.

Part of Pro
68

What is the Repository pattern?

Part of Pro
69

What are the different types of testing in PHP?

Part of Pro
70

How do you debug PHP applications effectively?

Part of Pro
71

What is PHPUnit and how do you write effective unit tests?

Part of Pro
72

What is code coverage and why is it important?

Part of Pro
73

Explain mocking and stubbing in PHP testing.

Part of Pro
74

What are generators and when should you use them?

Part of Pro Visual
75

How do you handle configuration in PHP applications?

Part of Pro
Expert 7
76

What are the best practices for database query optimization in PHP?

Part of Pro
77

How do you implement caching in PHP applications?

Part of Pro Visual
78

Explain the concept of immutability in PHP.

Part of Pro Visual
79

What is reflection in PHP and what are its use cases?

Part of Pro
80

What are SOLID principles and how do they apply to PHP?

Part of Pro
81

What is the difference between synchronous and asynchronous PHP?

Part of Pro Visual
82

Walk me through what happens when a PHP request is served.

Part of Pro Visual

No matches

Try a different filter or search term.

Know someone prepping for PHP? Send them this set.
Quick recap

PHP in pictures.

A quick recap of PHP in 33 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 29 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

71 of 82 PHP answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git