### PHP Type Casting Examples Source: https://github.com/php/doc-en/blob/master/_autodocs/types.md Demonstrates explicit type conversion for various data types in PHP. ```php (int)"123" // 123 (float)"3.14" // 3.14 (string)42 // "42" (array)"scalar" // ["scalar"] (object)["a"=>1] // stdClass with property (bool)1 // true ``` -------------------------------- ### Object Type Example Source: https://github.com/php/doc-en/blob/master/_autodocs/types.md Defines a simple class 'Point' and demonstrates how to instantiate an object and access its properties in PHP. ```php class Point { public $x; public $y; public function __construct(int $x, int $y) { $this->x = $x; $this->y = $y; } } $point = new Point(10, 20); echo $point->x; // 10 ``` -------------------------------- ### PHP gettype() Function Examples Source: https://github.com/php/doc-en/blob/master/_autodocs/types.md Examples showing the output of the `gettype()` function for various data types in PHP. ```php gettype(123) // "integer" gettype(3.14) // "double" gettype("str") // "string" gettype([]) // "array" gettype(true) // "boolean" gettype(null) // "NULL" gettype(\$obj) // "object" ``` -------------------------------- ### sapi_windows_cp_get Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Gets the current codepage for the SAPI. ```APIDOC ## sapi_windows_cp_get ### Description Gets the current codepage for the SAPI (Server Application Programming Interface) on Windows. ### Method N/A (This is a function, not an HTTP endpoint) ### Parameters #### Path Parameters - **kind** (string) - Required - Specifies the type of codepage to retrieve (e.g., 'input', 'output'). ### Returns `int`: The codepage number. ``` -------------------------------- ### Array Type Examples Source: https://github.com/php/doc-en/blob/master/_autodocs/types.md Illustrates the creation of simple, associative, and mixed arrays in PHP. Shows how numeric keys are reset upon appending elements and lists common array functions. ```php $simple = [1, 2, 3]; $associative = ['a' => 1, 'b' => 2]; $mixed = [ 'name' => 'John', 'age' => 30, 0 => 'first' ]; // Numeric keys reset on assignment \$arr = []; \$arr[] = 'a'; // index 0 \$arr[] = 'b'; // index 1 \$arr[10] = 'c'; // index 10 \$arr[] = 'd'; // index 11 ``` -------------------------------- ### Production php.ini Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Example php.ini settings for a production environment, focusing on security, performance, and reduced error display. ```ini error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE display_errors = Off display_startup_errors = Off log_errors = On error_log = /var/log/php-errors.log memory_limit = 128M max_execution_time = 30 post_max_size = 8M upload_max_filesize = 2M session.cookie_secure = On session.cookie_httponly = On session.cookie_samesite = "Strict" expose_php = Off disable_functions = "exec,passthru,shell_exec" ``` -------------------------------- ### Development php.ini Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Example php.ini settings for a development environment, emphasizing detailed error reporting and debugging. ```ini error_reporting = E_ALL display_errors = On display_startup_errors = On log_errors = On error_log = php_errors.log xdebug.mode = develop,debug xdebug.start_with_request = yes xdebug.client_host = localhost xdebug.client_port = 9003 memory_limit = 256M max_execution_time = 300 session.save_path = /tmp ``` -------------------------------- ### Integer Type Examples Source: https://github.com/php/doc-en/blob/master/_autodocs/types.md Illustrates how to declare integer variables in PHP using decimal, hexadecimal, octal, and binary formats. Includes constants for integer limits and size. ```php $value = 42; $negative = -15; $hex = 0x1A; $octal = 0755; $binary = 0b1010; // Constants PHP_INT_MAX // 9223372036854775807 PHP_INT_MIN // -9223372036854775808 PHP_INT_SIZE // 8 (bytes) ``` -------------------------------- ### Managing Session Data in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/constants.md Start a session with session_start() to enable session data persistence across requests. Use $_SESSION to store and retrieve session variables. ```php session_start(); $_SESSION['user_id'] = 42; echo $_SESSION['user_id']; // 42 ``` -------------------------------- ### Get Registered Hashing Algorithms Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/hash.md Retrieves a list of all hashing algorithms currently registered with the PHP hash extension. No setup is required. ```php array hash_algos(void) ``` -------------------------------- ### Get Windows Codepage (PHP) Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Retrieves the current codepage for the process. Accepts a 'kind' parameter. ```php int sapi_windows_cp_get(kind: string) ``` -------------------------------- ### Iterable Type Hint Example Source: https://github.com/php/doc-en/blob/master/_autodocs/types.md Shows how to use the 'iterable' type hint in a function to accept arrays or Traversable objects, processing each item in a loop. ```php function process(iterable $data): void { foreach ($data as $item) { // works with arrays or Iterator objects } } process([1, 2, 3]); process(new ArrayIterator([1, 2, 3])); ``` -------------------------------- ### String Type Examples Source: https://github.com/php/doc-en/blob/master/_autodocs/types.md Demonstrates various ways to declare strings in PHP, including single quotes, double quotes with interpolation, heredoc syntax, and nowdoc syntax. Lists common escape sequences. ```php $single = 'Hello'; $double = "World"; $interpolated = "Value: {$var}"; $heredoc = <<data[$name] ?? null; } // Called when setting undefined property public function __set(string $name, mixed $value): void { $this->data[$name] = $value; } // Called when checking isset() on undefined property public function __isset(string $name): bool { return isset($this->data[$name]); } // Called when calling undefined method public function __call(string $name, array $args): mixed { echo "Method $name called with " . count($args) . " args"; return null; } // Called on string conversion public function __toString(): string { return "Magic Object"; } // Called on var_export() public static function __set_state(array $properties): self { $obj = new self(); foreach ($properties as $key => $value) { $obj->$key = $value; } return $obj; } // Called on unserialize() public function __unserialize(array $data): void { $this->data = $data; } // Called on serialize() public function __serialize(): array { return $this->data; } // Constructor public function __construct() {} // Destructor public function __destruct() { // cleanup } } ``` -------------------------------- ### Get Constant Value (PHP) Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Returns the value of a defined constant. Requires the constant's name as a string argument. ```php mixed constant(name: string) ``` -------------------------------- ### Output Buffering Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Control output buffering size and compression. 'output_buffering' can be set to a size in KB or 'On' to buffer all output. 'zlib.output_compression' enables gzip compression. ```ini ; Enable output buffering output_buffering = 4096 ; Output handler (e.g., gzip) output_handler = "" ; Implicit flush implicit_flush = Off ; Zlib compression zlib.output_compression = Off zlib.output_compression_level = -1 ``` -------------------------------- ### Parse Date String Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/datetime.md Get detailed information about a given date/time string by parsing it with `date_parse`. Returns an associative array. ```php array date_parse(datetime: string) ``` -------------------------------- ### compact Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/array.md Creates an array containing variables and their values. ```APIDOC ## compact ### Description Creates an array containing variables and their values. ### Method `compact(var_name: array, var_names: array)` ### Parameters #### Path Parameters - **var_name** (array) - Required - Description not provided - **var_names** (array) - Required - Description not provided ``` -------------------------------- ### filter_input Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filter.md Gets a specific external variable by name and optionally filters it. It takes a type as a parameter and returns a mixed value. ```APIDOC ## filter_input ### Description Gets a specific external variable by name and optionally filters it. ### Parameters #### Query Parameters - **type** (int) - Required - The type of filter to apply. Defaults to 0. ### Returns `mixed` ``` -------------------------------- ### array_is_list Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/array.md Checks if an array is a list. A list is defined as an array with integer keys starting from 0 and incrementing without gaps. ```APIDOC ## array_is_list ### Description Checks if an array is a list. ### Method array_is_list ### Parameters #### Path Parameters - **array** (array) - Required - The array to check. ### Returns `bool` ``` -------------------------------- ### Get Specific Function Argument in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/funchand.md Use `func_get_arg` to retrieve a specific argument passed to a function, identified by its zero-based position. ```php mixed func_get_arg(position: int) ``` -------------------------------- ### Get/Set Windows VT100 Support (PHP) Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Manages VT100 support for a specified stream associated with a Windows console output buffer. Requires a stream resource. ```php bool sapi_windows_vt100_support(stream: resource) ``` -------------------------------- ### Get Default Timezone Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/datetime.md Retrieve the default timezone used by all date and time functions in the current PHP script using `date_default_timezone_get`. ```php string date_default_timezone_get(void) ``` -------------------------------- ### array_reduce Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/array.md Iteratively reduce the array to a single value using a callback function. Starts with an initial value and applies the callback to each element. ```APIDOC ## array_reduce ### Description Iteratively reduce the array to a single value using a callback function. ### Method array_reduce ### Parameters #### Path Parameters - **array** (array) - Optional - The input array. Defaults to null. ### Returns `mixed` ``` -------------------------------- ### PHP Runtime Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Set the default MIME type, timezone, and locale. Configure the random number generator engine for better randomness. ```ini ; Default MIME type default_mimetype = "text/html" ; Timezone date.timezone = "UTC" ; Locale intl.default_locale = "en_US" ; Enable strict types (strict_types=1 in files) ; Note: Must be per-file with declare(strict_types=1) ; Random number generator (random.engine) ; Values: mt19937, pcgone64, xoshiro256starstar, xoshiro256plus random.engine = mt19937 ``` -------------------------------- ### Create Custom Exceptions Source: https://github.com/php/doc-en/blob/master/_autodocs/errors.md Shows how to create custom exception classes, such as ValidationException and NetworkException, by extending the base Exception or RuntimeException. ```php class ValidationException extends Exception {} class NetworkException extends RuntimeException {} try { validateInput($data); } catch (ValidationException $e) { // handle validation errors } ``` -------------------------------- ### Throw and Catch Base Exception Source: https://github.com/php/doc-en/blob/master/_autodocs/errors.md Demonstrates how to throw a custom exception with a message and code, and how to catch it using a try-catch block to access its properties. ```php try { throw new Exception("Something went wrong", 1001); } catch (Exception $e) { echo $e->getMessage(); echo $e->getCode(); } ``` -------------------------------- ### Get PCRE Last Error Code Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/pcre.md Retrieves the error code from the most recent PCRE regex execution. This provides a numerical representation of the error. ```php int preg_last_error(void) ``` -------------------------------- ### Get Timezone Database Version Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/datetime.md Retrieve the version of the timezonedb used by PHP's date/time functions with `timezone_version_get`. This function requires no parameters. ```php string timezone_version_get(void) ``` -------------------------------- ### Database Connection Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Configure default database connection parameters for various database types like SQLite, PDO, and MySQLi. Set host, user, password, and port as needed. ```ini ; Default database host [sqlite] sqlite.assoc_case = 0 [pdo] pdo.dsn = "" [mysql] mysqli.default_host = localhost mysqli.default_user = "" mysqli.default_password = "" mysqli.default_port = 3306 ``` -------------------------------- ### Get Date/Time Information Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/datetime.md Retrieve an array containing detailed date and time information for a given Unix timestamp using the `getdate` function. ```php array getdate(timestamp: int) ``` -------------------------------- ### Use Namespaces in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/language-features.md Employ the 'use' keyword to import classes, functions, and constants from other namespaces. Aliases can be created using 'as' for brevity or to resolve naming conflicts. ```php use MyApp\Controllers\HomeController; use MyApp\Models\User as UserModel; use function MyApp\Helpers\format; use const MyApp\CONFIG; $controller = new HomeController(); $user = new UserModel(); echo format("text"); echo CONFIG; ``` -------------------------------- ### Get Line from File, Strip HTML Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Reads a line from a file pointer, stripping HTML tags. Specify maximum length and allowable tags. ```php string fgetss(handle: resource, length: int, allowable_tags: string) ``` -------------------------------- ### Get Sun Information Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/datetime.md Obtain information about sunrise, sunset, and twilight times for a given timestamp, latitude, and longitude using `date_sun_info`. Returns an array. ```php array date_sun_info(timestamp: int, latitude: float, longitude: float) ``` -------------------------------- ### for Loop Source: https://github.com/php/doc-en/blob/master/_autodocs/language-features.md Iterate a specific number of times with initialization, condition, and increment/decrement. ```php for ($i = 0; $i < 10; $i++) { echo $i; } ``` -------------------------------- ### Filesystem Functions Source: https://github.com/php/doc-en/blob/master/_autodocs/INDEX.md Offers functions for interacting with the file system, including reading and writing files, checking file existence and properties, directory operations, and path manipulation. ```APIDOC ## Filesystem Functions ### Description Functions for file and directory operations, including reading, writing, checking existence, directory manipulation, file listing, property retrieval, and path operations. ### Functions - `file_get_contents(filename)` - `fopen(path, mode)` - `fread(handle, length)` - `readfile(filename)` - `file_put_contents(filename, data)` - `fwrite(handle, string)` - `fclose(handle)` - `file_exists(filename)` - `is_file(filename)` - `is_dir(filename)` - `is_readable(filename)` - `mkdir(path)` - `rmdir(path)` - `chdir(directory)` - `getcwd()` - `scandir(directory)` - `glob(pattern)` - `opendir(path)` - `readdir(directory_handle)` - `filesize(filename)` - `filemtime(filename)` - `fileperms(filename)` - `stat(filename)` - `basename(path)` - `dirname(path)` - `realpath(path) ``` -------------------------------- ### Get PCRE Last Error Message Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/pcre.md Retrieves the error message from the most recent PCRE regex execution. Use this to understand specific regex failures. ```php string preg_last_error_msg(void) ``` -------------------------------- ### Initialize Incremental Hash Context Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/hash.md Initializes a new hashing context for incremental hashing. You can specify the algorithm, an optional key, and options. ```php HashContext hash_init(algo: string, key: string, options: array) ``` -------------------------------- ### PHP filter_input Function Signature Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filter.md Gets a specific external variable by name and optionally filters it. This function is useful for retrieving and sanitizing user input. ```php mixed filter_input(type: int) ``` -------------------------------- ### PHP Error Handling with Try-Catch-Finally Source: https://github.com/php/doc-en/blob/master/_autodocs/README.md Demonstrates robust error handling using try-catch-finally blocks for specific and general exceptions. Ensures cleanup actions are always performed. ```php try { $result = risky_operation(); } catch (FileNotFoundException $e) { error_log("File not found"); } catch (Exception $e) { error_log("Operation failed"); } finally { cleanup(); } ``` -------------------------------- ### Validate PHP Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Use this command to validate the overall PHP configuration, including `php.ini` files. ```bash ; Validate configuration php --ini ``` -------------------------------- ### Open a ZIP Directory Entry Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/zip.md Use `zip_entry_open` to open a directory entry for reading from a zip archive. This function takes a zip resource and returns a boolean indicating success. ```php bool zip_entry_open(zip_dp: resource) ``` -------------------------------- ### symlink Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Creates a symbolic link pointing to a target file or directory. ```APIDOC ## symlink ### Description Creates a symbolic link. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method Not applicable (PHP function) ### Endpoint Not applicable (PHP function) ### Request Example ```php bool symlink(target: string, link: string) ``` ### Response #### Success Response - Returns `true` on success, `false` on failure. #### Response Example ```php true ``` ``` -------------------------------- ### Abstract Classes in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/language-features.md Illustrates the use of abstract classes and abstract methods in PHP, requiring subclasses to implement abstract methods. ```php abstract class Shape { abstract public function area(): float; public function describe(): void { echo "Area: " . $this->area(); } } class Circle extends Shape { private float $radius; public function __construct(float $radius) { $this->radius = $radius; } public function area(): float { return pi() * $this->radius ** 2; } } ``` -------------------------------- ### Get Current Unix Timestamp Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/datetime.md Obtain the current Unix timestamp (seconds since the Unix Epoch) using the `time` function. It takes no arguments and returns an integer. ```php int time(void) ``` -------------------------------- ### Get Local Time Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/datetime.md Retrieve the local time information for a given Unix timestamp using `localtime`. The `associative` parameter determines the return type (array or boolean). ```php array localtime(timestamp: int, associative: bool) ``` -------------------------------- ### Use Exception Chaining Source: https://github.com/php/doc-en/blob/master/_autodocs/errors.md Illustrates exception chaining by catching a PDOException and re-throwing it as a custom DatabaseException, preserving the original exception as the previous one. ```php try { $db->query($sql); } catch (PDOException $e) { throw new DatabaseException( "Query failed", 0, $e // previous exception ); } ``` -------------------------------- ### Set PHP Configuration at Runtime Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Use ini_set() to change configuration directives during script execution. ini_get() retrieves current values, and ini_restore() reverts to the original setting. ```php ini_set('display_errors', '1'); ini_set('error_reporting', E_ALL); ini_set('memory_limit', '256M'); // Check current value echo ini_get('memory_limit'); // Get all settings print_r(ini_get_all()); // Restore original value ini_restore('display_errors'); ``` -------------------------------- ### Use finally for Cleanup Source: https://github.com/php/doc-en/blob/master/_autodocs/errors.md Demonstrates the use of the `finally` block to ensure cleanup code, like closing a file handle, is executed regardless of whether an exception occurred. ```php $handle = fopen('file.txt', 'r'); try { // read file } finally { if (is_resource($handle)) { fclose($handle); } } ``` -------------------------------- ### PHP-FPM Configuration File Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md This INI-style configuration file defines global settings and pool-specific parameters for PHP-FPM, including process management, listening addresses, and logging. ```ini [global] ; PID file location pid = /run/php-fpm.pid ; Error log error_log = /var/log/php-fpm.log ; Log level log_level = notice ; Pool name [www] ; Listen address listen = 127.0.0.1:9000 listen = /run/php-fpm.sock listen.owner = www-data listen.group = www-data listen.mode = 0660 ; Process manager pm = dynamic pm.max_children = 20 pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 10 pm.max_requests = 500 ; Worker environment user = www-data group = www-data ; Catch output catch_workers_output = yes ; Slowlog slowlog = /var/log/php-fpm-slow.log request_slowlog_timeout = 5s ; Process status pm.status_path = /status ping.path = /ping ``` -------------------------------- ### Copy File Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Copies an existing file to a new location. The destination path is implicitly determined by the context or requires additional parameters not shown in this signature. ```php bool copy(from: string) ``` -------------------------------- ### Get Number of Function Arguments in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/funchand.md Use `func_num_args` to determine the total number of arguments that were passed to the current function. This is helpful for functions designed to handle a variable argument list. ```php int func_num_args(void) ``` -------------------------------- ### pack Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Packs data into a binary string according to a specified format. ```APIDOC ## pack ### Description Packs data into a binary string according to a specified format. ### Method N/A (This is a function, not an HTTP endpoint) ### Parameters #### Path Parameters - **format** (string) - Required - The format string specifying how to pack the data. - **values** (mixed) - Required - The values to pack. ### Returns `string`: The packed binary string. ``` -------------------------------- ### Copy Hashing Context Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/hash.md Creates a copy of an existing hashing context. This is useful when you need to compute multiple hashes from the same initial state without re-initializing. ```php HashContext hash_copy(context: HashContext) ``` -------------------------------- ### Session Management Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Configure session save handler, path, cookie settings, and garbage collection. Secure session handling with 'session.cookie_secure' and 'session.cookie_httponly'. ```ini ; Session save handler session.save_handler = files ; Session save path session.save_path = "/var/lib/php/sessions" ; Session cookie name session.name = PHPSESSID ; Session cookie lifetime (seconds) session.cookie_lifetime = 0 ; Session gc probability session.gc_probability = 1 session.gc_divisor = 1000 ; Session gc maxlifetime (seconds) session.gc_maxlifetime = 1440 ; Use cookies for session ID session.use_cookies = On ; Only send cookies over HTTPS session.cookie_secure = On ; Prevent JavaScript access session.cookie_httponly = On ; SameSite cookie attribute session.cookie_samesite = "Strict" ``` -------------------------------- ### touch Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Sets the access and modification times of a file. ```APIDOC ## touch ### Description Sets access and modification time of file. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method Not applicable (PHP function) ### Endpoint Not applicable (PHP function) ### Request Example ```php bool touch(filename: string, atime: int) ``` ### Response #### Success Response - Returns `true` on success, `false` on failure. #### Response Example ```php true ``` ``` -------------------------------- ### usleep Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Delays execution in microseconds. ```APIDOC ## usleep ### Description Delays execution in microseconds. ### Method `usleep` ### Parameters #### Path Parameters - **microseconds** (int) - Required - The number of microseconds to sleep. ### Returns `void` ``` -------------------------------- ### Memory and Limit Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Set limits for script memory usage, POST data size, file uploads, input variables, and execution times. Adjust these based on application requirements and server resources. ```ini ; Maximum memory per script memory_limit = 128M ; Maximum POST data size post_max_size = 8M ; Maximum uploaded file size upload_max_filesize = 2M ; Maximum string variable length max_input_vars = 1000 ; Maximum execution time (seconds) max_execution_time = 30 ; Maximum input time (seconds) max_input_time = 60 ``` -------------------------------- ### Default __autoload() implementation Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/spl.md The default implementation for __autoload() provided by the SPL extension. It is typically used as a fallback or base for custom autoloaders. ```php void spl_autoload(class: string) ``` -------------------------------- ### lchown Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Changes the user ownership of a symbolic link. ```APIDOC ## lchown ### Description Changes user ownership of symlink. ### Method `lchown(filename: string, user: string)` ### Parameters #### Path Parameters - **filename** (string) - Required - Description: The path to the symbolic link. - **user** (string) - Required - Description: The name or ID of the new user. ### Returns `bool` ``` -------------------------------- ### Anonymous Functions (Closures) in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/language-features.md Demonstrates defining and using anonymous functions (closures) in PHP, including accessing outer scope variables with 'use'. ```php $multiply = function(int $x, int $y): int { return $x * $y; }; echo $multiply(3, 4); // 12 // Access outer scope with use $factor = 2; $multiply_by_factor = function(int $x) use ($factor): int { return $x * $factor; }; echo $multiply_by_factor(5); // 10 ``` -------------------------------- ### sapi_windows_cp_set Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Sets the process codepage for the SAPI on Windows. ```APIDOC ## sapi_windows_cp_set ### Description Sets the process codepage for the SAPI on Windows. ### Method N/A (This is a function, not an HTTP endpoint) ### Parameters #### Path Parameters - **codepage** (int) - Required - The codepage number to set. ### Returns `bool`: `true` on success, `false` on failure. ``` -------------------------------- ### Check if File or Directory Exists Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Verifies the existence of a file or directory at the specified path. ```php bool file_exists(filename: string) ``` -------------------------------- ### dirname Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Returns the parent directory's path. ```APIDOC ## dirname ### Description Returns a parent directory's path ### Signature `string dirname(path: string)` ### Parameters #### Path Parameters - **path** (string) - Required - The path string. ### Returns - `string` - The directory name component of the path. ``` -------------------------------- ### array Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/array.md Create an array. This is a fundamental language construct for creating arrays. ```APIDOC ## array ### Description Create an array. ### Parameters #### Path Parameters - **values** (mixed) - Required - Description: The values to include in the array. ### Returns `array` ``` -------------------------------- ### Class Definition in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/language-features.md Shows the basic structure of a PHP class, including properties, constructor, methods, and static methods. ```php class User { // Properties private string $name; protected int $age = 0; public string $email; // Constructor public function __construct(string $name) { $this->name = $name; } // Methods public function getName(): string { return $this->name; } private function validate(): bool { return strlen($this->name) > 0; } // Static method public static function create(string $name): self { return new self($name); } } $user = new User("John"); echo $user->getName(); // John ``` -------------------------------- ### Set Windows Codepage (PHP) Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Sets the codepage for the current process. Requires the codepage integer as an argument. ```php bool sapi_windows_cp_set(codepage: int) ``` -------------------------------- ### Traits in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/language-features.md Shows how to use traits in PHP to achieve code reuse by including methods from a trait into a class. ```php trait Loggable { public function log(string $message): void { echo "[LOG] $message"; } } class Service { use Loggable; } $service = new Service(); $service->log("Started"); // [LOG] Started ``` -------------------------------- ### link Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Creates a hard link to a target file. ```APIDOC ## link ### Description Create a hard link. ### Method `link(target: string, link: string)` ### Parameters #### Path Parameters - **target** (string) - Required - Description: The existing file to link to. - **link** (string) - Required - Description: The name of the new hard link to create. ### Returns `bool` ``` -------------------------------- ### Fill Array with Values Using Keys Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/array.md Fills an array with specified values using a given set of keys. Ideal for creating arrays from a list of keys and a single value. ```php array array_fill_keys(keys: array, value: mixed) ``` -------------------------------- ### Setting and Accessing Cookies in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/constants.md Use setcookie() to send a cookie to the client and $_COOKIE to retrieve cookie values sent by the client in subsequent requests. ```php setcookie('user', 'John', time() + 3600); echo $_COOKIE['user']; ``` -------------------------------- ### Return all registered __autoload() functions Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/spl.md Retrieves an array containing all currently registered __autoload() callback functions. This is useful for inspecting or managing autoloading configurations. ```php array spl_autoload_functions(void) ``` -------------------------------- ### Error Handling Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Configure PHP's error reporting, display, and logging behavior. Use 'display_errors = On' for development and 'log_errors = On' with 'error_log' for production. ```ini ; Report all PHP errors error_reporting = E_ALL ; Display errors (development only) display_errors = On ; Log errors to file (production) log_errors = On error_log = /var/log/php-errors.log ; Error reporting to stderr (FPM) error_log = "php-fpm" ; Display startup errors display_startup_errors = On ; Track errors in variables track_errors = Off ``` -------------------------------- ### Security Configuration Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md Enhance security by disabling dangerous functions and classes, enabling file uploads, restricting file access with 'open_basedir', and hiding the PHP version. ```ini ; Disable functions for security disable_functions = "exec,passthru,shell_exec,proc_open" ; Disable classes disable_classes = "" ; Allow file uploads file_uploads = On ; Open basedir restriction open_basedir = "/var/www:/tmp" ; Prevent exposing PHP version expose_php = Off ``` -------------------------------- ### fflush Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Flushes the output buffer to a file. ```APIDOC ## fflush ### Description Flushes the output to a file ### Signature `bool fflush(stream: resource)` ### Parameters #### Path Parameters - **stream** (resource) - Required - The file pointer resource. ### Returns - `bool` - Returns `true` on success, `false` on failure. ``` -------------------------------- ### fnmatch Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/filesystem.md Matches a filename against a given pattern. ```APIDOC ## fnmatch ### Description Match filename against a pattern ### Signature `bool fnmatch(pattern: string, filename: string)` ### Parameters #### Path Parameters - **pattern** (string) - Required - The pattern to match against. - **filename** (string) - Required - The filename to check. ### Returns - `bool` - Returns `true` if the filename matches the pattern, `false` otherwise. ``` -------------------------------- ### Verify PHP Syntax Source: https://github.com/php/doc-en/blob/master/_autodocs/configuration.md This command checks the syntax of your PHP files for errors. ```bash # Verify php.ini syntax php -l ``` -------------------------------- ### PHP gettype() Return Values Source: https://github.com/php/doc-en/blob/master/_autodocs/constants.md Demonstrates the string values returned by the gettype() function for various data types. ```php var_dump(gettype(123)); // "integer" var_dump(gettype(1.23)); // "double" var_dump(gettype("string")); // "string" ``` -------------------------------- ### Configure Error Reporting for Production Source: https://github.com/php/doc-en/blob/master/_autodocs/errors.md Configures error reporting for production environments to log errors to a file and hide them from the screen. ```php // Production error_reporting(E_ALL); ini_set('display_errors', '0'); ini_set('log_errors', '1'); ini_set('error_log', '/var/log/php-errors.log'); ``` -------------------------------- ### Accessing Server and Execution Information in PHP Source: https://github.com/php/doc-en/blob/master/_autodocs/constants.md The $_SERVER superglobal provides information about the server environment, execution details, and request headers. ```php $_SERVER['REQUEST_METHOD']; // GET, POST, etc. $_SERVER['REQUEST_URI']; // URI path $_SERVER['HTTP_HOST']; // Host name $_SERVER['SCRIPT_NAME']; // Script filename $_SERVER['PHP_SELF']; // Current script $_SERVER['SERVER_ADDR']; // Server IP $_SERVER['SERVER_PORT']; // Server port $_SERVER['REMOTE_ADDR']; // Client IP $_SERVER['REMOTE_HOST']; // Client hostname ``` -------------------------------- ### define Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Defines a new named constant. ```APIDOC ## define ### Description Defines a new named constant. ### Method N/A (This is a function, not an HTTP endpoint) ### Parameters #### Path Parameters - **constant_name** (string) - Required - The name of the constant to define. ### Returns `bool`: `true` on success, `false` on failure. ``` -------------------------------- ### Register an __autoload() implementation Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/spl.md Registers a callable function to be executed when a class is not found. Allows specifying whether to throw an exception on failure and if the callback should be prepended to the stack. ```php bool spl_autoload_register(callback: callable, throw: bool, prepend: bool) ``` -------------------------------- ### __autoload Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/classobj.md Attempts to load an undefined class. This function is typically used for autoloading class definitions. ```APIDOC ## __autoload ### Description Attempts to load an undefined class. ### Parameters #### Path Parameters - **class** (string) - Required - The name of the class to load. ### Returns `void` ``` -------------------------------- ### intdiv Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/math.md Performs integer division. ```APIDOC ## intdiv ### Description Integer division. ### Signature `int intdiv(num1: int, num2: int)` ### Parameters #### Path Parameters - **num1** (int) - Required - The dividend. - **num2** (int) - Required - The divisor. ``` -------------------------------- ### Function Handling Functions Source: https://github.com/php/doc-en/blob/master/_autodocs/INDEX.md Utilities for handling functions, including callback execution, retrieving function information, creating anonymous functions, and accessing function arguments. ```APIDOC ## Function Handling Functions ### Description Functions for handling callbacks, retrieving function information, creating anonymous functions, and accessing function arguments. ### Functions - `call_user_func(callback)` - `call_user_func_array(callback, params)` - `function_exists(function_name)` - `get_defined_functions()` - `create_function(args, code)` (deprecated) - `func_get_arg(arg_num)` - `func_num_args()` ``` -------------------------------- ### while and do-while Loops Source: https://github.com/php/doc-en/blob/master/_autodocs/language-features.md Iterate code blocks based on a condition. 'do-while' guarantees at least one execution. ```php while ($condition) { // executes while condition is true } do { // executes at least once } while ($condition); ``` -------------------------------- ### each Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/array.md Returns the current key and value pair from an array and advances the array cursor. ```APIDOC ## each ### Description Returns the current key and value pair from an array and advances the array cursor. ### Method `each(void)` ``` -------------------------------- ### Return by Reference Source: https://github.com/php/doc-en/blob/master/_autodocs/language-features.md Return a reference to a variable instead of a copy, allowing the caller to modify the original variable. ```php class Container { private $value = 0; public function &getValue(): int { return $this->value; } } $container = new Container(); $ref = &$container->getValue(); $ref = 42; ``` -------------------------------- ### Generate Windows CTRL Event (PHP) Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/misc.md Sends a CTRL event to another process on Windows. Requires the event type as an integer. ```php bool sapi_windows_generate_ctrl_event(event: int) ``` -------------------------------- ### list Source: https://github.com/php/doc-en/blob/master/_autodocs/api-reference/array.md Assigns variables as if they were an array. ```APIDOC ## list ### Description Assigns variables as if they were an array. ### Method `list(var: mixed, vars: mixed)` ### Parameters #### Path Parameters - **var** (mixed) - Required - Description not provided - **vars** (mixed) - Required - Description not provided ``` -------------------------------- ### Configure Error Reporting for Development Source: https://github.com/php/doc-en/blob/master/_autodocs/errors.md Sets error reporting to display all errors and errors to the screen for development environments. ```php // Development error_reporting(E_ALL); ini_set('display_errors', '1'); ```