Skip to main content

27. HaPHPiness - Best things in PHP

This section highlights modern PHP features and the overall "happiness" of the ecosystem, as inspired by haphpiness.com.

What are Named Arguments?​

Junior

Answer: Named arguments (introduced in PHP 8.0) allow you to pass values by parameter name instead of position. See PHP 8.0 Features


What are Union Types and Intersection Types?​

Junior

Answer: Union types (8.0) allow multiple types for a parameter; Intersection types (8.1) require a value to satisfy multiple type constraints. See PHP 8.0 Features


What are Enums?​

Junior

Answer: Enumerations (8.1) provide type safety for a fixed set of named constants. See PHP 8.1 Features


What are str_contains(), str_starts_with(), and str_ends_with()?​

Junior

Answer: These are consistent, readable functions for common string operations introduced in PHP 8.0. Detailed HaPHPiness Guide


What is Array Unpacking with String Keys?​

Junior

Answer: Introduced in PHP 8.1, the spread operator (...) now supports string keys for merging arrays. Detailed HaPHPiness Guide


What is the Built-in Development Server?​

Junior

Answer: PHP includes a simple web server for development purposes, started with php -S localhost:8000. Detailed HaPHPiness Guide


What are Arrow Functions?​

Junior

Answer: Introduced in PHP 7.4, they offer a concise syntax for short closures with automatic variable capture. Detailed HaPHPiness Guide


What are Match Expressions?​

Junior

Answer: A safer, stricter alternative to switch that returns a value (PHP 8.0). Detailed HaPHPiness Guide


What is the Null Coalescing Operator?​

Junior

Answer: The ?? operator (and ??= assignment) provides a clean way to handle null values and defaults. Detailed HaPHPiness Guide


What are Numeric Literal Separators?​

Junior

Answer: Using underscores to improve the readability of large numbers (e.g., 1_000_000). Detailed HaPHPiness Guide


What are Fibers?​

Middle

Answer: Lightweight coroutines for non-blocking I/O (PHP 8.1). See PHP 8.1 Features


What are Attributes?​

Middle

Answer: First-class metadata (annotations) natively supported by the PHP engine since 8.0. Detailed HaPHPiness Guide


What is the First-class Callable Syntax?​

Middle

Answer: A clean way to create a Closure from a function or method using (...). See PHP 8.1 Features


What is the Nullsafe Operator?​

Middle

Answer: The ?-> operator allows safe method/property access on potentially null values. See PHP 8.0 Features


What are Property Hooks?​

Middle

Answer: Logic for get and set defined directly on property declarations (PHP 8.4). See PHP 8.4 Features


What is Asymmetric Visibility?​

Middle

Answer: Different visibility for reading and writing a property (e.g., public private(set)). See PHP 8.4 Features


What is the Pipe Operator?​

Middle

Answer: A way to chain function calls from left to right using |> (PHP 8.5). See PHP 8.5 Features


What is array_is_list()?​

Middle

Answer: A function to check if an array is a sequential list with keys starting from 0. Detailed HaPHPiness Guide


What are WeakMaps?​

Middle

Answer: Maps where keys are objects that don't prevent those objects from being garbage collected. Detailed HaPHPiness Guide


What are Named Capture Groups in preg_match?​

Middle

Answer: Using (?P<name>...) in regex to get named matches instead of just numeric indices. Detailed HaPHPiness Guide


What is the Spaceship Operator?​

Middle

Answer: The <=> operator for three-way comparison, returning -1, 0, or 1. Detailed HaPHPiness Guide


What is Array Destructuring with Keys?​

Middle

Answer: Pulling specific values out of an associative array using the [...] syntax. Detailed HaPHPiness Guide


What is #[\NoDiscard]?​

Senior

Answer: An attribute that warns if a function's return value is ignored (PHP 8.5). Detailed HaPHPiness Guide


What are Fatal Error Backtraces?​

Senior

Answer: Since PHP 8.5, fatal errors (like timeouts) include a full stack trace for easier debugging. Detailed HaPHPiness Guide


What is the URI Extension?​

Senior

Answer: A built-in, immutable, and standards-compliant URL parsing extension (PHP 8.5). Detailed HaPHPiness Guide


What is FFI (Foreign Function Interface)?​

Senior

Answer: Allows calling C functions and using C data structures directly from PHP (7.4+). Detailed HaPHPiness Guide


What are PHPStan and Psalm?​

Senior

Answer: Static analysis tools that provide TypeScript-grade type safety for PHP codebases. Detailed HaPHPiness Guide


What is NativePHP?​

Senior

Answer: A framework for building native desktop and mobile applications using PHP and Laravel. Detailed HaPHPiness Guide