- What are filters in PHP
- What is the difference between validation and sanitization
- What is filter_var used for
- What are common validation filters
- What are common sanitization filters
- What is filter_input used for
- What is a common mistake when using filters
- What is FILTER_VALIDATE_INT with options
- What is JSON in PHP
- What is json_encode used for
- What is json_decode used for
- What is the difference between decoding as object and array
- What is a common issue with json_decode
- How do you handle JSON errors
- What is UTF-8 requirement in JSON
- What is a common mistake with JSON
- What are exceptions in PHP
- What is try catch in PHP
- What is finally block
- What is the difference between Exception and Error
- What is throw used for
- What is a custom exception
- What is the difference between multiple catch blocks
- What is a common mistake with exceptions
- What is OOP in PHP
- What is a class and an object
- What is encapsulation
- What is inheritance
- What is polymorphism
- What is abstraction
- What are access modifiers
- What is a constructor
- What is $this
- What is static keyword
- What is an interface
- What is an abstract class
- What is a trait
- What is a common mistake in OOP
- What is MySQL and how is it used with PHP
- What are the main types of SQL queries
- What is the difference between MySQLi and PDO
- What are prepared statements and why are they important
- What is SQL injection
- What is indexing and why is it important
- What is the difference between WHERE and HAVING
- What is a primary key
- What is a foreign key
- What is normalization
- What is a JOIN
- What is the difference between INNER JOIN and LEFT JOIN
- What is LIMIT used for
- What is a transaction
- What is COMMIT and ROLLBACK
- What is a common mistake when working with MySQL
- What is AJAX and how is it used with PHP
- What is the main benefit of AJAX
- What is the role of PHP in AJAX
- What is the difference between synchronous and asynchronous requests
- How do you send an AJAX request using JavaScript
- How do you handle AJAX request in PHP
- What format is commonly used with AJAX
- What is a common mistake with AJAX and PHP
- What is CORS and why is it important
What are filters in PHP
Filters are used to validate and sanitize external input like form data, URLs, and emails
What is the difference between validation and sanitization
Validation checks if data meets a rule
Sanitization cleans or modifies data to make it safe
What is filter_var used for
It applies a filter to a variable
$email = "[email protected]"; var_dump(filter_var($email, FILTER_VALIDATE_EMAIL));
What are common validation filters
FILTER_VALIDATE_EMAIL
FILTER_VALIDATE_URL
FILTER_VALIDATE_INT
What are common sanitization filters
FILTER_SANITIZE_STRING
FILTER_SANITIZE_EMAIL
FILTER_SANITIZE_URL
What is filter_input used for
It gets input from superglobals and applies a filter
$name = filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING);
What is a common mistake when using filters
Assuming sanitization alone is enough without validation
What is FILTER_VALIDATE_INT with options
It allows range validation
filter_var(10, FILTER_VALIDATE_INT, ["options" => ["min_range" => 1, "max_range" => 100]]);
What will this return
var_dump(filter_var("123abc", FILTER_VALIDATE_INT));
false
What is JSON in PHP
JSON is a lightweight data format used to exchange data between systems
What is json_encode used for
Converts PHP data into a JSON string
$data = ["name" => "Amr", "age" => 23]; echo json_encode($data);
What is json_decode used for
Converts JSON string into PHP data
$json = '{"name":"Amr","age":23}';
$obj = json_decode($json);
$arr = json_decode($json, true);
What is the difference between decoding as object and array
Default returns object
Passing true returns associative array
What is a common issue with json_decode
Invalid JSON returns null
How do you handle JSON errors
Use json_last_error or JSON_THROW_ON_ERROR
json_decode($json, true, 512, JSON_THROW_ON_ERROR);
What is UTF-8 requirement in JSON
JSON expects UTF-8 encoded data
What is a common mistake with JSON
Forgetting to set correct headers in APIs
header("Content-Type: application/json");
What are exceptions in PHP
Exceptions are used to handle errors in a controlled way instead of stopping execution abruptly
What is try catch in PHP
It is used to catch and handle exceptions
try {
throw new Exception("Error occurred");
} catch (Exception $e) {
echo $e->getMessage();
}
What is finally block
It runs regardless of whether an exception occurs or not
try {
// code
} catch (Exception $e) {
// handle
} finally {
// always runs
}
What is the difference between Exception and Error
Exception can be handled using try catch
Error represents serious issues and may not be recoverable
What is throw used for
It is used to manually trigger an exception
What is a custom exception
A user-defined exception class
class MyException extends Exception {}
What is the difference between multiple catch blocks
You can catch different exception types separately
try {
// code
} catch (TypeError $e) {
} catch (Exception $e) {
}
What is a common mistake with exceptions
Catching exceptions and ignoring them without handling or logging
What will this return
try {
throw new Exception("Test");
} catch (Exception $e) {
echo "Caught";
}
Caught
What is OOP in PHP
Object Oriented Programming organizes code using classes and objects to improve structure, reuse, and maintainability
What is a class and an object
A class is a blueprint
An object is an instance of that class
class User {
public $name;
}
$user = new User();
What is encapsulation
It restricts direct access to data using access modifiers like public, private, protected
What is inheritance
A class can extend another class and reuse its properties and methods
class Admin extends User {}
What is polymorphism
Same method name behaves differently depending on the object
What is abstraction
Hides implementation details and shows only essential features
What are access modifiers
public accessible everywhere
private accessible only
protected accessible
What is a constructor
A special method that runs when an object is created
function __construct($name) {
$this->name = $name;
}
What is $this
Refers to the current object instance
What is static keyword
Used for properties or methods that belong to the class not the object
class Test {
public static function run() {
return "ok";
}
}
What is an interface
Defines methods that a class must implement
interface Logger {
public function log($msg);
}
What is an abstract class
A class that cannot be instantiated and may contain abstract methods
abstract class Base {
abstract public function run();
}
What is a trait
Used to reuse code across multiple classes
trait Loggable {
public function log() {}
}
What is a common mistake in OOP
Mixing responsibilities in one class instead of keeping single responsibility
What is MySQL and how is it used with PHP
MySQL is a relational database used to store and manage data. PHP connects to it to perform CRUD operations
What are the main types of SQL queries
SELECT to read data
INSERT to add data
UPDATE to modify data
DELETE to remove data
What is the difference between MySQLi and PDO
MySQLi supports only MySQL
PDO supports multiple databases and provides a consistent interface
What are prepared statements and why are they important
They separate query structure from data
They prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
What is SQL injection
A security attack where malicious input changes the query logic
What is indexing and why is it important
Indexes improve query speed by allowing faster data lookup
What is the difference between WHERE and HAVING
WHERE filters before grouping
HAVING filters after grouping
What is a primary key
A unique identifier for each row
What is a foreign key
A field that links to a primary key in another table
What is normalization
Organizing data to reduce redundancy and improve integrity
What is a JOIN
Combines data from multiple tables
What is the difference between INNER JOIN and LEFT JOIN
INNER JOIN returns matching rows only
LEFT JOIN returns all rows from left table and matching from right
What is LIMIT used for
Restricts number of returned rows
What is a transaction
A set of operations executed as one unit
What is COMMIT and ROLLBACK
COMMIT saves changes
ROLLBACK undoes changes
What is a common mistake when working with MySQL
Not using prepared statements and exposing the app to SQL injection
What is AJAX and how is it used with PHP
AJAX stands for Asynchronous JavaScript and XML. It allows sending requests to the server and receiving data without reloading the page
What is the main benefit of AJAX
Improves user experience by updating parts of the page without full reload
What is the role of PHP in AJAX
PHP processes the request on the server and returns data, usually JSON
What is the difference between synchronous and asynchronous requests
Synchronous blocks execution until response returns
Asynchronous continues execution while waiting for response
How do you send an AJAX request using JavaScript
Using fetch or XMLHttpRequest
fetch("api.php")
.then(res => res.json())
.then(data => console.log(data));
How do you handle AJAX request in PHP
Read input and return response
echo json_encode(["status" => "ok"]);
What format is commonly used with AJAX
JSON
What is a common mistake with AJAX and PHP
Not setting correct response headers
header("Content-Type: application/json");
What is CORS and why is it important
Controls access between different domains
What will this return
If PHP returns JSON and JS parses it
You get a JavaScript object ready to use
Continue Your PHP Interview Preparation
If you found this guide helpful, don’t miss the rest of our comprehensive PHP interview series:
- 👉 PHP Interview Questions Part 1
- 👉 PHP Interview Questions Part 2
- 👉 PHP Interview Questions Part 3
- 👉 PHP Interview Questions Part 4
By going through the full series, you’ll build a strong foundation in PHP and be fully prepared to tackle interviews with confidence.
No Comments