All questions
Showing of 82What is PHP and what does it stand for?
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:
Last attempt -
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.
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 ↓
What are the differences between echo and print in PHP?
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:
Last attempt -
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.
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 ↓
Explain the difference between include, require, include_once, and require_once.
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:
Last attempt -
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.
includeemits anE_WARNINGfor a missing file, and the script keeps running.requirethrows anErrorfor a missing file, which ends the script unless caught. Before PHP 8.0 it raised a fatalE_COMPILE_ERROR.include_onceandrequire_onceload a file only once. A later call for the same file returnstruewithout 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.
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 ↓
What are PHP tags and what are the different types?
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:
Last attempt -
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 theshort_open_tagsetting, 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.
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 ↓
What are the main data types in PHP?
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:
Last attempt -
PHP's data types fall into three groups: scalar types that hold one value, compound types that hold several, and special types.
- Scalar:
boolfortrueorfalse,intandfloatfor numbers, andstringfor text. A float is also called adouble. - Compound:
array,objectandcallable.iterableis a type alias for anarrayor aTraversableobject. - Special:
nullfor no value, andresourcefor 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.
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 ↓
Explain the difference between == and === operators.
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:
Last attempt -
== 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.
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 ↓
What is type juggling in PHP?
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:
Last attempt -
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.
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 ↓
What are superglobal variables in PHP?
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:
Last attempt -
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,$_POSTand$_COOKIEcombined 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.
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 ↓
How do you declare constants in PHP and what's the difference between define() and const?
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:
Last attempt -
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.
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 ↓
What is the null coalescing operator and how does it work?
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:
Last attempt -
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.
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 ↓
Explain the spaceship operator in PHP.
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:
Last attempt -
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.
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 ↓
What is the difference between break and continue statements?
What are variable functions in PHP?
Explain the difference between pass by value and pass by reference.
What are anonymous functions (closures) in PHP?
What is the difference between func_get_args() and using parameters?
Explain variable scope in PHP.
What is method chaining and how do you implement it?
Explain the difference between array_merge() and array_combine().
What are the different error levels in PHP?
What is the difference between single-quoted and double-quoted strings in PHP?
What is the difference between GET and POST requests in PHP?
What are the main principles of OOP in PHP?
What's the difference between indexed and associative arrays?
How do you check if a key exists in an array?
Explain the difference between abstract classes and interfaces.
What are PHP traits and when would you use them?
What are magic methods in PHP?
Explain late static binding in PHP.
What are PHP namespaces and why are they important?
What are the differences between array_map(), array_filter(), and array_reduce()?
Explain the difference between errors and exceptions in PHP.
How do you create and handle custom exceptions?
What is the finally block and when is it executed?
What is PDO and what are its advantages over MySQLi?
What are prepared statements and why are they important?
Explain database transactions in PHP.
What is the N+1 query problem and how do you solve it?
What's the difference between sessions and cookies?
How do you implement secure session management?
What is session fixation and how do you prevent it?
What is SQL injection and how do you prevent it?
Explain Cross-Site Scripting (XSS) and prevention methods.
What is CSRF and how do you protect against it?
How do you properly hash passwords in PHP?
What are the security implications of file uploads?
What are the differences between REST and SOAP?
How do you handle API authentication in PHP?
What is CORS and how do you handle it in PHP?
How do you implement rate limiting in PHP APIs?
What are PHP CodeSniffer and PHP CS Fixer?
What is Composer and how does it work?
Explain PSR standards and their importance.
What is the difference between require and autoloading?
How does PHP handle memory management?
What does declare(strict_types=1) change, and where does it apply?
What is opcode caching and how does it improve performance?
Explain lazy loading and eager loading in the context of PHP.
What are typed properties in PHP and their benefits?
Explain union types in PHP 8.
What are attributes (annotations) in PHP 8?
What is the match expression and how does it differ from switch?
Explain constructor property promotion in PHP 8.
What are enumerations (enums) in PHP?
Explain the Singleton pattern and its implementation in PHP.
What is dependency injection and why is it important?
Explain the MVC pattern in PHP applications.
What is the Repository pattern?
What are the different types of testing in PHP?
How do you debug PHP applications effectively?
What is PHPUnit and how do you write effective unit tests?
What is code coverage and why is it important?
Explain mocking and stubbing in PHP testing.
What are generators and when should you use them?
How do you handle configuration in PHP applications?
What are the best practices for database query optimization in PHP?
How do you implement caching in PHP applications?
Explain the concept of immutability in PHP.
What is reflection in PHP and what are its use cases?
What are SOLID principles and how do they apply to PHP?
What is the difference between synchronous and asynchronous PHP?
Walk me through what happens when a PHP request is served.
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
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.
PHP cheatsheet
- Syntax & types01
- Functions & arrays02
- Classes & objects03
- Errors, debugging & tests04
- Databases with PDO05
- Sessions & security06
- Requests & APIs07
- Composer & tooling08
- Design patterns & SOLID09
- Runtime & performance10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 29 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in71 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.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.