Advertisement

Information Technology

PHP Interview Questions & Answers

Server-side scripting language purpose-built for web dynamic logic.

46topics 322questions last updated
Advertisement

Arrays in PHP

All 7 questions
  1. An array in PHP is a data structure that lets you store multiple values in a single variable, and PHP supports indexed arrays where elements are accessed by a numeric position, ass…

  2. You can add an element to the end of an array using square bracket syntax or the array_push function, remove an element using unset for a specific key or array_pop to remove the la…

  3. array_map applies a given function to every element of an array and returns a new array with the transformed values, array_filter returns a new array containing only the elements t…

  4. The sort function reorders an array by value and reindexes the keys numerically, asort sorts an array by value while preserving the original keys, which is useful for associative a…

  5. Array destructuring lets you assign multiple array elements directly to individual variables in a single statement, using either the list function or the equivalent shorthand squar…

Asynchronous PHP (ReactPHP & Swoole)

All 7 questions
  1. Traditional PHP code runs synchronously, meaning each statement waits for the previous one to fully complete before starting, including blocking on slow operations like network req…

  2. ReactPHP is a library that provides an event driven, non blocking input and output model for PHP, built around a central event loop that continuously checks for completed operation…

  3. Swoole is a PHP extension, written in C, that adds native support for coroutines, asynchronous input and output, and high performance networking directly into PHP, letting you writ…

  4. Swoole coroutines let you write code that reads like ordinary sequential PHP, such as directly calling a database query and using its result on the next line, while Swoole automati…

  5. Applications well suited for asynchronous PHP include real time chat applications, WebSocket servers, high throughput APIs handling many concurrent requests, long polling notificat…

Basics & Types

All 7 questions
  1. PHP is a widely used, open source scripting language designed specifically for web development, letting you embed code directly within HTML pages or run it as standalone scripts, a…

  2. PHP supports several basic data types including integers for whole numbers, floats for decimal numbers, strings for text, booleans for true or false values, arrays for collections…

  3. Type juggling refers to PHP's automatic conversion of a value from one type to another based on the context it is used in, such as automatically converting a string containing digi…

  4. A variable variable lets you use the value of one variable as the name of another variable, referenced using a double dollar sign syntax, which can be useful in specific dynamic sc…

  5. PHP provides standard comparison operators like equal to, not equal to, greater than, and less than, along with the spaceship operator, which compares two values and returns negati…

Caching Strategies in PHP

All 7 questions
  1. Caching means temporarily storing the result of an expensive operation, such as a slow database query or a complex calculation, so that future requests needing the same data can re…

  2. File based caching stores cached data as files on the server's disk, which is simple to set up and requires no additional infrastructure but is generally slower to read and write c…

  3. Page caching stores an entire rendered HTML page and serves it directly for future identical requests, avoiding any PHP execution at all, query caching stores the results of specif…

  4. Cache invalidation means removing or updating cached data once it becomes stale or outdated, and it is considered difficult because you must carefully track every place that could…

  5. Laravel provides a unified Cache facade that lets you store, retrieve, and manage cached data using a consistent, simple syntax regardless of which underlying cache driver, such as…

Closures & Anonymous Functions

All 7 questions
  1. An anonymous function, also called a closure, is a function without a name that can be assigned to a variable, passed as an argument to another function, or returned from a functio…

  2. By default, an anonymous function in PHP does not have access to variables from the surrounding scope where it was defined, so the use keyword explicitly lets you import specific o…

  3. By default, variables imported using the use keyword are captured by value, meaning the closure receives a snapshot of that variable's value at the time the closure was defined, an…

  4. Arrow functions provide a more concise syntax for writing short, single expression closures, automatically capturing variables from the enclosing scope by value without needing an…

  5. A closure can be passed into a class constructor or method as a way to inject custom behavior without requiring a full separate class or interface implementation, letting the recei…

  1. Composer is a dependency management tool for PHP that lets you declare the external libraries your project depends on, and it automatically downloads, installs, and manages those l…

  2. The composer.json file is the central configuration file for a Composer managed project, declaring the project's required dependencies along with their acceptable version constrain…

  3. The composer.json file specifies the version constraints for your dependencies, such as accepting any compatible version within a major release, while the composer.lock file record…

  4. Semantic versioning structures a version number as major, minor, and patch, where major version increases indicate breaking changes, minor increases add backward compatible new fea…

  5. Composer's autoloading feature, most commonly configured using the PSR-4 standard, maps a namespace prefix to a specific directory in your project, and once configured, PHP automat…

Constants & Superglobals

All 7 questions
  1. A constant is a named value that, once defined, cannot be changed for the rest of the script's execution, unlike a regular variable whose value can be reassigned at any time, and c…

  2. Superglobals are built in PHP variables that are always accessible from any scope throughout a script, including inside functions and classes, without needing to explicitly declare…

  3. You should always check whether a specific key exists before accessing it, commonly using the null coalescing operator to provide a safe default value if the key is missing, and yo…

  4. A class constant is defined within a class using the const keyword and is accessed using the scope resolution operator alongside the class name, scoping the constant specifically t…

  5. The $_SERVER superglobal contains a wide range of information about the current request and the server environment, including the requested URL, the HTTP method used, the client's…

Date & Time Handling

All 7 questions
  1. The DateTime class provides an object oriented way to represent, manipulate, and format dates and times, offering significantly more flexibility than the older procedural date func…

  2. The format method on a DateTime object accepts a format string made up of special characters that each represent a specific piece of the date or time, such as uppercase Y for a fou…

  3. You can create a DateInterval object specifying a duration, such as three days or one month, and then use the DateTime object's add or sub method to shift a date forward or backwar…

  4. PHP's DateTime class lets you associate a specific DateTimeZone with a date, and explicitly setting the correct time zone is important because a date and time value has fundamental…

  5. The diff method available on a DateTime object calculates the difference between that date and another given date, returning a DateInterval object containing properties representin…

Dependency Injection & Service Containers

All 7 questions
  1. Dependency injection is a design pattern where a class receives the objects it depends on from an outside source, typically through its constructor, rather than creating those depe…

  2. A service container, also called a dependency injection container, is a tool that manages the creation and wiring together of an application's objects, automatically resolving and…

  3. Autowiring is a service container feature that inspects a class's constructor type hints using PHP's reflection capabilities, automatically determining what dependencies that class…

  4. Binding an interface to a concrete implementation tells the service container which specific class should be used whenever a class requests that interface as a dependency, which is…

  5. A singleton binding, sometimes called shared, ensures the container returns the exact same instance of an object every time it is requested throughout the application's lifecycle,…

Deployment & Hosting for PHP Applications

All 7 questions
  1. PHP applications can be deployed using shared hosting, where your application runs alongside many other customers' sites on the same server at a low cost but with limited control,…

  2. PHP-FPM, or FastCGI Process Manager, is a PHP implementation that manages a pool of worker processes ready to handle incoming PHP requests, working alongside a web server like Ngin…

  3. A typical deployment process involves running the application's test suite to verify the code changes have not introduced any regressions, running Composer to install production de…

  4. Environment variables let you store configuration values, such as database credentials or API keys, outside of your actual application code, and a .env file provides a convenient w…

  5. A reverse proxy sits in front of your PHP application, handling tasks such as terminating SSL and TLS encryption, serving static files directly without involving PHP at all, compre…

Design Patterns in PHP

All 7 questions
  1. A design pattern is a proven, reusable solution to a commonly occurring problem in software design, representing a shared vocabulary and approach that experienced developers have r…

  2. The Singleton pattern ensures a class has only one single instance throughout the application and provides a global point of access to that instance, which is sometimes used for th…

  3. The Factory pattern centralizes the logic for creating objects within a dedicated factory class or method, letting the rest of your code request an object without needing to know t…

  4. The Strategy pattern defines a common interface for a family of related algorithms, letting you encapsulate each specific algorithm as its own separate class, and the code using th…

  5. The Observer pattern lets an object, called the subject, maintain a list of dependent objects, called observers, and automatically notify all of them whenever a significant event o…

Eloquent ORM & Doctrine ORM

All 7 questions
  1. An Object Relational Mapper, or ORM, lets you interact with a database using ordinary PHP objects and method calls rather than writing raw SQL queries directly, with Eloquent, Lara…

  2. An Eloquent model is a PHP class that extends Laravel's base Model class, and by convention, Eloquent automatically assumes the model corresponds to a database table with the plura…

  3. Eloquent relationships are defined as methods on a model that describe how it relates to another model, such as hasMany for a one to many relationship like a user having many order…

  4. The N plus one query problem occurs when retrieving a list of records and then separately querying related data for each individual record in a loop, resulting in one initial query…

  5. In Doctrine, entity classes are plain PHP objects with no knowledge of how they are persisted, and all the actual database interaction, such as saving, updating, or deleting an ent…

Email Sending in PHP (PHPMailer & SMTP)

All 7 questions
  1. PHP's built in mail function sends an email by relying on the server's local mail transfer agent, but it offers limited control over important details like proper authentication, f…

  2. PHPMailer is a popular, widely used library that provides a more robust and flexible way to send emails from PHP, supporting secure SMTP authentication, HTML formatted emails, file…

  3. SMTP authentication requires your application to provide valid credentials, typically a username and password, when connecting to an SMTP server to send an email, proving to the re…

  4. SPF, or Sender Policy Framework, specifies which mail servers are authorized to send email on behalf of your domain, DKIM, or DomainKeys Identified Mail, adds a cryptographic signa…

  5. PHPMailer lets you set the isHTML method to true to send richly formatted HTML content instead of plain text, and it provides an addAttachment method for including file attachments…

Error & Exception Handling

All 7 questions
  1. A PHP error traditionally represents a problem detected by the PHP engine itself, such as calling an undefined function, and historically these were handled differently from except…

  2. A try catch block lets you wrap code that might throw an exception inside a try section, and if an exception occurs, execution immediately jumps to a matching catch block that spec…

  3. A finally block contains code that always executes after the try and any matching catch block, regardless of whether an exception was thrown or caught, making it well suited for cl…

  4. You create a custom exception by defining a class that extends PHP's built in Exception class, or a more specific built in exception, optionally adding your own additional properti…

  5. Exception chaining lets you pass an original exception as the previous parameter when constructing and throwing a new exception, preserving the full chain of what actually caused t…

File Handling & File System Functions

All 7 questions
  1. file_get_contents provides a simple, convenient way to read an entire file's contents into a single string in one function call, which is perfect for smaller files, while fopen ope…

  2. file_put_contents writes data to a file, completely overwriting any existing content by default, while passing the FILE_APPEND flag instead adds the new content to the end of the e…

  3. The file_exists function checks whether a given path exists as either a file or a directory, while functions like filesize and filemtime retrieve specific metadata about a file, su…

  4. The scandir function returns an array of all files and subdirectories within a given directory, mkdir creates a new directory including the option to create nested parent directori…

  5. The flock function lets you acquire an exclusive or shared lock on a file before reading from or writing to it, preventing race conditions where multiple processes or requests atte…

File Upload Handling

All 7 questions
  1. When a user submits a form containing a file input with the proper multipart encoding, PHP automatically stores information about the uploaded file in the $_FILES superglobal, incl…

  2. The move_uploaded_file function safely moves a file that was uploaded through an HTTP POST request from its temporary server location to a permanent destination you specify, and it…

  3. You should validate an uploaded file's actual content type using functions that inspect the file's real content, such as checking its MIME type through PHP's fileinfo extension, ra…

  4. When a file input is configured to accept multiple files using an array style field name, the $_FILES superglobal organizes the data slightly differently, storing each attribute, s…

  5. Uploaded file names, since they originate from user input, should never be trusted or used directly as the final storage file name without sanitization, since a malicious file name…

Form Handling & Validation

All 7 questions
  1. Form data submitted using the GET method is appended directly to the URL as a query string and accessible through the $_GET superglobal, which is appropriate for non sensitive requ…

  2. Validating form data ensures that the information submitted by a user actually meets your application's expectations before it is processed or stored, with common checks including…

  3. Client side validation, while valuable for providing immediate feedback to a legitimate user without requiring a full page reload, can always be bypassed by a malicious user who di…

  4. The filter_var function applies a specified filter to a given value, either validating that the value matches an expected format, such as a valid email address or URL, returning fa…

  5. Modern frameworks like Laravel provide a dedicated validation system that lets you define validation rules for each form field using a concise, declarative syntax, automatically ru…

Functions & Scope

All 7 questions
  1. You define a function in PHP using the function keyword followed by a name, a list of parameters the function accepts inside parentheses, and a body of code enclosed in curly brace…

  2. Variable scope determines where in your code a particular variable can be accessed, and in PHP, a variable defined inside a function is local to that function by default and cannot…

  3. A default parameter value lets you specify a fallback value that is used if the caller does not explicitly provide that argument, making certain parameters effectively optional, wh…

  4. Named arguments let you specify function arguments by explicitly stating the parameter name they correspond to, rather than relying purely on their position in the function's param…

  5. A regular local variable inside a function is reset to its initial value every single time the function is called, while a variable declared as static retains its value between sep…

Generators & Iterators

All 7 questions
  1. A generator is a special kind of function that uses the yield keyword to produce a sequence of values one at a time, pausing its execution after each yield and resuming exactly whe…

  2. The Iterator interface defines a set of methods, including current, key, next, rewind, and valid, that a class must implement to define exactly how it should be iterated over, and…

  3. The IteratorAggregate interface requires implementing just a single method, getIterator, which returns an object that itself implements Iterator, often conveniently a generator or…

  4. In addition to yielding values out to the calling code, a generator can also receive a value sent into it using the send method, which resumes the generator's execution and makes t…

  5. The yield from construct lets a generator delegate to another iterable, such as a different generator function or a plain array, effectively flattening that iterable's values into…

Interfaces & Abstract Classes

All 7 questions
  1. An interface defines a set of method signatures that any class implementing that interface must provide, without specifying any actual implementation details itself, acting as a co…

  2. An abstract class cannot be instantiated directly and is meant to be extended by other classes, and unlike an interface, it can contain both fully implemented methods that subclass…

  3. You generally choose an interface when you want to define a pure contract without providing any shared implementation, especially when unrelated classes need to guarantee the same…

  4. Polymorphism lets you write code that operates on an interface type without needing to know the specific concrete class it is actually working with at runtime, meaning a function a…

  5. Yes, an interface can extend one or more other interfaces using the extends keyword, meaning any class implementing the more specific extended interface must also fulfill the requi…

JSON Handling in PHP

All 7 questions
  1. The json_encode function converts a PHP array or object into a JSON formatted string, which is the standard, widely used data format for exchanging information between different sy…

  2. The json_decode function parses a JSON formatted string and converts it back into a corresponding PHP value, returning a PHP object by default, or an associative array if you pass…

  3. By default, json_decode returns null if it encounters invalid JSON, but null is also a valid JSON value itself, making it ambiguous whether decoding actually failed or the JSON gen…

  4. The json_encode function accepts an optional flags parameter that lets you control formatting behavior, such as JSON_PRETTY_PRINT to produce nicely indented, human readable output…

  5. The JsonSerializable interface requires implementing a single method, jsonSerialize, which returns the exact data structure that should actually be used when json_encode processes…

Laravel Framework Essentials

All 7 questions
  1. Laravel is a full featured, open source PHP framework that follows the MVC architectural pattern and provides built in solutions for common web development needs, including routing…

  2. Artisan is Laravel's built in command line interface, providing a wide range of commands that automate common development tasks, such as generating boilerplate code for a new contr…

  3. Laravel routes are defined in dedicated route files, typically mapping a specific URL pattern and HTTP method to either a closure or, more commonly for larger applications, a speci…

  4. Blade is Laravel's built in templating engine, providing a clean, concise syntax for common templating needs like displaying variables, conditional logic, and loops, along with pow…

  5. Eloquent is Laravel's built in ORM, letting each database table be represented by a corresponding model class, and following the Active Record pattern, each model instance directly…

Magic Methods

All 7 questions
  1. Magic methods are special methods in PHP, always prefixed with a double underscore, that PHP automatically calls in response to certain actions performed on an object, with __const…

  2. The __get magic method is automatically called when code attempts to read an inaccessible or undefined property on an object, and __set is similarly called when attempting to write…

  3. The __call magic method is automatically invoked whenever code attempts to call a method on an object that does not actually exist as a defined method, receiving the attempted meth…

  4. The __toString magic method defines what string should be produced whenever an object is used in a context that expects a string, such as being directly echoed or concatenated with…

  5. The __invoke magic method lets you call an object instance directly using function call syntax, as if the object itself were a callable function, which is useful for creating class…

MVC Architecture in PHP

All 7 questions
  1. MVC divides an application into three interconnected components, with the Model responsible for representing data and business logic, often interacting directly with the database,…

  2. A controller's primary responsibility is to receive an incoming request, coordinate with the appropriate model to retrieve or modify data, and determine which view should be render…

  3. While a Model often does directly correspond to a database table, particularly when using an Active Record based ORM like Eloquent, a well designed Model in MVC should also encapsu…

  4. Views are responsible purely for presenting data to the user, typically as HTML, and should contain minimal logic beyond simple conditionals and loops needed for basic display purp…

  5. A typical request first arrives at a front controller, usually a single index.php entry point, which routes the request based on its URL to the appropriate specific controller and…

Namespaces & Autoloading

All 7 questions
  1. A namespace lets you group related classes, functions, and constants under a common named prefix, solving the problem of naming collisions that can occur when two different classes…

  2. The use keyword lets you import a specific class from another namespace at the top of a PHP file, allowing you to refer to that class using just its short name for the remainder of…

  3. PSR-4 is a widely adopted autoloading standard that establishes a direct correspondence between a class's namespace and its physical file location, meaning a class named App\Servic…

  4. Within a namespaced file, referencing a class name without any prefix is interpreted relative to the current namespace, a fully qualified name starting with a leading backslash alw…

  5. A common and effective convention organizes namespaces to mirror an application's logical architecture, such as placing all data model classes under an App\Models namespace, busine…

  1. The four core principles are encapsulation, which means bundling data and the methods that operate on it together while controlling access using visibility modifiers, inheritance,…

  2. The public modifier allows a property or method to be accessed from anywhere, including outside the class entirely, protected restricts access to the class itself and any classes t…

  3. The extends keyword lets a child class inherit the properties and methods of a parent class, automatically gaining access to everything the parent defines as public or protected, a…

  4. A static property or method belongs to the class itself rather than to any specific instance, meaning it is accessed using the class name and scope resolution operator rather than…

  5. The readonly modifier lets you declare a property that can only be assigned a value once, typically within the constructor, and any subsequent attempt to modify that property from…

Package Development & Publishing with Composer

All 7 questions
  1. A Composer package is a self contained, reusable piece of PHP code, complete with its own composer.json file describing its dependencies and autoloading rules, that can be installe…

  2. Packagist is the primary public package repository for Composer, serving as a central directory where PHP package authors submit their packages so that any other developer can easi…

  3. A well structured package composer.json typically includes a clear description explaining what the package does, an appropriate open source license declaration, author information,…

  4. As the author of a published package, correctly following semantic versioning by only incrementing the major version number when you make a genuinely breaking change is critically…

  5. A Laravel package typically includes a dedicated service provider class that Laravel automatically discovers and loads based on package auto discovery configuration within composer…

PDO & Databases

All 7 questions
  1. PDO, or PHP Data Objects, provides a consistent, unified interface for accessing many different database systems, including MySQL, PostgreSQL, and SQLite, meaning the same general…

  2. A prepared statement separates a SQL query's structure from the actual data values being used within it, first sending the query template to the database with placeholders for any…

  3. Named placeholders let you use descriptive names, prefixed with a colon, within your SQL query instead of plain question marks, and when executing the statement, you provide an ass…

  4. A transaction lets you group multiple database operations together so that they are treated as a single atomic unit, meaning either every operation within the transaction succeeds…

  5. By setting the PDO::ATTR_ERRMODE attribute to PDO::ERRMODE_EXCEPTION, you configure PDO to throw a proper PDOException whenever a database error occurs, such as a malformed query o…

Performance Optimization & OPcache

All 7 questions
  1. OPcache is a built in PHP extension that stores precompiled script bytecode in shared memory, meaning PHP does not need to parse and compile the same PHP source file from scratch o…

  2. Common approaches include using a profiling tool to measure exactly how much time is spent in different parts of your code, examining slow database query logs to identify expensive…

  3. The N plus one query problem occurs when code retrieves a list of records and then executes an additional separate query for each individual record's related data within a loop, re…

  4. PHP-FPM's pm.max_children setting controls the maximum number of worker processes available to handle simultaneous requests, and setting this value too low can cause requests to qu…

  5. Beyond database queries specifically, general performance optimization involves ensuring expensive operations, such as calling an external API or performing a complex calculation,…

PHP 8 Features (Attributes, Enums, Match, Nullsafe Operator)

All 7 questions
  1. The match expression compares a value against several possible conditions and returns a corresponding result, similar in purpose to a switch statement, but match uses strict type c…

  2. The nullsafe operator, written as a question mark followed by an arrow, lets you safely access a property or call a method on an object that might be null, automatically short circ…

  3. A pure enum defines a fixed set of named cases without any underlying scalar value associated with each case, while a backed enum additionally associates each case with a specific…

  4. Attributes let you attach structured, machine readable metadata directly to a class, method, or property using a specific bracket based syntax, which can then be read and acted upo…

  5. Constructor property promotion lets you declare and initialize a class property directly within the constructor's parameter list, simply by adding a visibility modifier before the…

PHP CLI Scripting

All 7 questions
  1. You run a PHP script from the command line by invoking the php executable followed by the script's file name, and unlike running PHP through a web server, a command line script doe…

  2. The $argv superglobal is an array containing every argument passed to the script from the command line, with the first element always being the script's own file name, and $argc co…

  3. The getopt function lets you define a set of expected short and long option flags, such as a verbose flag or an option requiring a value like a specific output file path, and autom…

  4. Rather than writing standalone command line scripts from scratch, frameworks like Laravel and Symfony provide a structured console component that lets you define a custom command a…

  5. Cron is a standard Linux utility for scheduling recurring tasks, and you can configure it to run a PHP script at specific times or intervals, such as every night at midnight, by ad…

PHP with Docker

All 7 questions
  1. Docker lets you package an application along with all of its dependencies, including a specific PHP version, required extensions, and system libraries, into a portable, self contai…

  2. A Dockerfile is a text file containing a series of instructions describing exactly how to build a Docker image, typically starting with a FROM instruction specifying a base PHP ima…

  3. Docker Compose lets you define an entire multi container application, such as an Nginx web server, a PHP-FPM application container, and a MySQL database container, all within a sin…

  4. A multi stage build lets you use multiple FROM statements within a single Dockerfile, where an early stage might include development tools and dependencies needed only for building…

  5. Environment variables passed into a container let the exact same Docker image behave differently based on its deployment context, such as connecting to a different database host in…

Regular Expressions in PHP

All 7 questions
  1. A regular expression is a specialized pattern used to describe and match specific sequences of characters within text, and PHP's preg_match function checks whether a given string c…

  2. The dot matches any single character except a newline, the asterisk means the preceding character or group can appear zero or more times, and the plus sign means the preceding char…

  3. The preg_replace function searches a string for text matching a given pattern and replaces every match with a specified replacement string, and by wrapping specific parts of your p…

  4. The preg_split function divides a string into an array of substrings based on matches of a regular expression pattern acting as the delimiter, which is significantly more flexible…

  5. A named capture group lets you assign a descriptive name to a specific part of your pattern using a special syntax, and when a match is found, you can access that specific captured…

RESTful API Development with PHP

All 7 questions
  1. A RESTful API is a style of web API design that treats data as a collection of resources, each identified by a specific URL, and uses standard HTTP methods to indicate the intended…

  2. HTTP status codes provide a standardized way for an API to communicate the outcome of a request, with codes in the 200 range indicating success, such as 200 for a successful GET re…

  3. Session based authentication relies on a server side session, typically identified through a cookie, which works well for traditional web applications but is less ideal for APIs co…

  4. A well designed API typically uses plural nouns to represent resource collections, such as slash products rather than slash product, nests related resources logically, such as slas…

  5. Rate limiting restricts how many requests a specific client, typically identified by an API key or IP address, can make within a given time window, protecting your API's backend re…

Routing & Middleware

All 7 questions
  1. Routing is the process of mapping an incoming request's URL and HTTP method to a specific piece of code responsible for handling it, typically a controller method or a closure, and…

  2. Middleware is a piece of code that sits within the request handling pipeline, running either before a request reaches its intended route handler, after the handler produces a respo…

  3. A middleware pipeline chains together multiple middleware functions, with each middleware receiving both the current request and a reference to the next piece of code in the chain,…

  4. A route parameter, typically defined using curly braces within a route pattern, captures a specific dynamic segment of the URL and makes that captured value available to the route'…

  5. A route group lets you wrap several related route definitions together, applying shared configuration such as a common URL prefix, a specific middleware that should run for every r…

  1. SQL injection happens when untrusted user input is inserted directly into a SQL query string, allowing an attacker to manipulate the query itself and potentially read, modify, or d…

  2. Cross site scripting occurs when an attacker manages to inject malicious script code into a web page that is then executed in another user's browser, often by submitting that scrip…

  3. Passwords must never be stored as plain text because if a database is ever breached, plain text passwords would immediately expose every user's actual password, whereas a properly…

  4. Cross site request forgery tricks a logged in user's browser into unknowingly submitting a request to an application they are authenticated with, such as changing their account set…

  5. Allowing users to upload files introduces significant security risk if not carefully validated, since an attacker could attempt to upload a disguised executable script rather than…

Sessions & Cookies

All 7 questions
  1. A session lets a web application store data related to a specific visitor on the server side and retrieve that same data on later requests from the same visitor, and since HTTP its…

  2. A cookie is a small piece of data that the server asks the visitor's browser to store and send back with future requests to the same website, and unlike a session, where the actual…

  3. The httponly flag on a cookie tells the browser to prevent that cookie from being accessed through client side JavaScript, which significantly reduces the risk that a cross site sc…

  4. PHP periodically runs a garbage collection process that removes session data files that have not been accessed within a configured maximum lifetime, controlled by the session.gc_ma…

  5. Session fixation is an attack where an attacker tricks a victim into using a session identifier that the attacker already knows, then waits for the victim to log in, at which point…

Static Analysis (PHPStan & Psalm)

All 7 questions
  1. Static analysis is the process of examining source code without actually executing it, looking for patterns that indicate likely bugs, such as calling a method that does not exist,…

  2. PHPStan organizes its checks into numbered levels, starting from a lenient level zero that only catches the most obvious, clear cut errors, up to a very strict maximum level that e…

  3. Static analysis tools rely heavily on type information to understand what kind of value a variable, parameter, or return value is expected to hold, and while PHP's native type decl…

  4. A baseline file records every currently existing issue that static analysis finds in a codebase at a specific point in time, effectively telling the tool to ignore those specific a…

  5. Taint analysis tracks how data flows through an application starting from an untrusted source, such as user submitted form input, following that data through every function call an…

Strings & String Functions

All 7 questions
  1. PHP lets you create strings using single quotes, double quotes, or the heredoc syntax for longer multiline text, and the dot operator lets you concatenate, meaning join together, t…

  2. Single quoted strings treat almost everything inside them literally, meaning a variable name written inside a single quoted string is not replaced with its value and most escape se…

  3. PHP provides a large built in library of string functions covering the most common text processing needs, including strlen to find out how many characters a string contains, substr…

  4. PHP's original string functions were designed around the assumption that every character occupies exactly one byte, which works fine for plain English text using the ASCII characte…

  5. The sprintf function builds a formatted string based on a template containing special placeholders, each describing exactly how a corresponding value should be inserted and formatt…

Symfony Framework Essentials

All 7 questions
  1. Symfony is a mature, widely used PHP framework for building web applications, offering a well structured approach with strong conventions around routing, controllers, services, and…

  2. Symfony's routing system maps an incoming URL and HTTP method to a specific controller method responsible for handling it, and routes can be defined in several different ways depen…

  3. Symfony's service container is responsible for creating and managing the various service objects an application depends on, such as a database connection, a mailer, or a custom bus…

  4. Doctrine is the ORM most commonly used together with Symfony, and it lets you represent each database table as a corresponding PHP class, called an entity, with each property on th…

  5. Symfony's event system lets one part of an application dispatch an event at a meaningful moment, such as right after a new user registers, without needing to know anything about wh…

Template Engines (Blade & Twig)

All 7 questions
  1. A template engine provides a dedicated syntax for generating dynamic HTML output, letting you embed variables, loops, and conditional logic directly within an otherwise mostly stat…

  2. Both Blade and Twig automatically escape variable output by default, meaning any special HTML characters within a displayed value are converted into their safe text equivalents bef…

  3. Template inheritance lets you define a single base layout template containing shared structural elements common to every page, such as the header, navigation menu, and footer, alon…

  4. Both Blade and Twig provide their own clean, concise syntax for common control structures like foreach loops and if statements, which read more naturally within an HTML context com…

  5. Blade components and Twig macros both let you define a reusable, self contained piece of template markup once, such as a styled button, a form input field, or an alert message box,…

  1. A trait is a mechanism for reusing a set of methods across multiple classes that are not necessarily related to each other through a normal parent child inheritance relationship, a…

  2. Duplicating the exact same method across several different classes means that if a bug is ever found or the behavior needs to change, that same fix or change has to be manually app…

  3. When a class uses two or more traits that each define a method sharing the exact same name, PHP raises a fatal error since it cannot automatically determine which of the conflictin…

  4. A trait can define an abstract method, meaning it declares the method's name and signature without providing any actual implementation body, which forces any class that uses that t…

  5. A trait can define its own properties, including static properties, and when a trait is used by a particular class, that trait's properties effectively become properties of that sp…

Type Declarations & Strict Types

All 7 questions
  1. Type declarations let you explicitly specify the expected data type of a function's parameters and its return value directly within the function's signature, such as declaring that…

  2. By default, PHP operates in what is called coercive typing mode, meaning it will automatically attempt to convert a value to the expected declared type if possible, such as silentl…

  3. A nullable type, indicated by placing a question mark directly before the type name, means a parameter or return value can either be that specific declared type or explicitly be nu…

  4. A readonly property, once initialized, typically within a class's constructor, can never be modified again afterward, and attempting to reassign a readonly property's value anywher…

  5. Type declarations provide concrete, machine readable information about what kind of value is expected in a given context, and both static analysis tools and modern code editors rel…

Unit Testing with PHPUnit

All 7 questions
  1. PHPUnit is the most widely used testing framework in the PHP ecosystem, providing the tools needed to write, organize, and run automated tests against your code, and a unit test sp…

  2. An assertion is a statement within a test that checks whether an actual value matches an expected value, and if that check fails, the entire test is immediately marked as failed wi…

  3. The arrange act assert pattern is a widely recommended way to structure the internal logic of an individual test, first arranging any necessary setup, such as creating the objects…

  4. A mock object is a fake, controlled substitute for a real dependency, created specifically for use within a test, and using a mock instead of the actual real dependency lets you te…

  5. Test coverage measures what percentage of a codebase's actual lines or branches of code are executed at least once while running the full test suite, and while reasonably high test…

WordPress Plugin & Theme Development

All 7 questions
  1. A WordPress theme controls the visual appearance and layout of a website, including how pages, posts, and other content are actually displayed to visitors, while a plugin adds new…

  2. WordPress hooks provide the primary mechanism through which plugins and themes can modify or extend WordPress's core behavior without needing to directly edit WordPress's own core…

  3. A WordPress plugin at its simplest consists of at least one PHP file placed within its own dedicated folder inside the wp content plugins directory, and that main PHP file must beg…

  4. A custom post type lets you define an entirely new kind of content beyond WordPress's default built in posts and pages, such as a dedicated product, event, or testimonial content t…

  5. Since WordPress plugins and themes are extremely widely used, running on a very large percentage of all websites, a security vulnerability discovered in a single popular plugin can…

XML Handling in PHP

All 7 questions
  1. XML, short for Extensible Markup Language, is a structured text format used for representing hierarchical data using nested tags, similar in spirit to HTML but designed specificall…

  2. SimpleXML converts an entire XML document into a tree of PHP objects, letting you navigate nested elements simply by chaining together property access using the arrow operator, sim…

  3. While SimpleXML is convenient for straightforward reading tasks, the DOM extension provides a more complete and powerful representation of an XML document as a full tree of node ob…

  4. XPath is a standardized query language specifically designed for selecting specific nodes from within an XML document, using a path like syntax similar in some ways to navigating f…

  5. An XML external entity attack exploits a feature of the XML specification that allows a document to define a custom entity referencing an external resource, such as a local file on…