Survive The Deep End: PHP Security
Table Of Contents
  1. What are filters in PHP
  2. What is the difference between validation and sanitization
  3. What is filter_var used for
  4. What are common validation filters
  5. What are common sanitization filters
  6. What is filter_input used for
  7. What is a common mistake when using filters
  8. What is FILTER_VALIDATE_INT with options
  9. What is JSON in PHP
  10. What is json_encode used for
  11. What is json_decode used for
  12. What is the difference between decoding as object and array
  13. What is a common issue with json_decode
  14. How do you handle JSON errors
  15. What is UTF-8 requirement in JSON
  16. What is a common mistake with JSON
  17. What are exceptions in PHP
  18. What is try catch in PHP
  19. What is finally block
  20. What is the difference between Exception and Error
  21. What is throw used for
  22. What is a custom exception
  23. What is the difference between multiple catch blocks
  24. What is a common mistake with exceptions
  25. What is OOP in PHP
  26. What is a class and an object
  27. What is encapsulation
  28. What is inheritance
  29. What is polymorphism
  30. What is abstraction
  31. What are access modifiers
  32. What is a constructor
  33. What is $this
  34. What is static keyword
  35. What is an interface
  36. What is an abstract class
  37. What is a trait
  38. What is a common mistake in OOP
  39. What is MySQL and how is it used with PHP
  40. What are the main types of SQL queries
  41. What is the difference between MySQLi and PDO
  42. What are prepared statements and why are they important
  43. What is SQL injection
  44. What is indexing and why is it important
  45. What is the difference between WHERE and HAVING
  46. What is a primary key
  47. What is a foreign key
  48. What is normalization
  49. What is a JOIN
  50. What is the difference between INNER JOIN and LEFT JOIN
  51. What is LIMIT used for
  52. What is a transaction
  53. What is COMMIT and ROLLBACK
  54. What is a common mistake when working with MySQL
  55. What is AJAX and how is it used with PHP
  56. What is the main benefit of AJAX
  57. What is the role of PHP in AJAX
  58. What is the difference between synchronous and asynchronous requests
  59. How do you send an AJAX request using JavaScript
  60. How do you handle AJAX request in PHP
  61. What format is commonly used with AJAX
  62. What is a common mistake with AJAX and PHP
  63. What is CORS and why is it important
  64. What will this return

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:

By going through the full series, you’ll build a strong foundation in PHP and be fully prepared to tackle interviews with confidence.

Amr Abdelkarem

I’m Amr Abdelkarem, a PHP Backend Developer with 5+ years of experience building backend-driven systems using PHP, REST APIs, MySQL, and PostgreSQL. I’ve worked on e-commerce workflows, payment integrations, shipping automation, and scalable business logic in production environments. I also have previous experience with WordPress backend development and Django-based systems, and I’m currently focused on Laravel and backend architecture. My certifications include IBM’s Developing Front-End Apps with React, plus certifications in Cloud Computing, HTML/CSS/JavaScript, Software Engineering, Python for Data Science, and Databases and SQL.

No Comments

Leave a Comment

Course Recommendations