====== PHP RFC: Trim Form Feed ====== * Version: 1.0 * Date: 2025-12-28 * Author: Weilin Du, lamentxu@163.com * Status: Draft * Implementation: https://github.com/php/php-src/pull/20788 ===== Introduction ===== The ''trim()'', ''ltrim()'', and ''rtrim()'' functions strip whitespace (or other characters) from the beginning and/or end of a string. When the second parameter (''$characters'') is omitted, these functions use a default set of characters. Currently, this default set includes: * ''" "'' (ASCII 32 (0x20)), an ordinary space. * ''"\t"'' (ASCII 9 (0x09)), a tab. * ''"\n"'' (ASCII 10 (0x0A)), a new line (line feed). * ''"\r"'' (ASCII 13 (0x0D)), a carriage return. * ''"\0"'' (ASCII 0 (0x00)), the NUL-byte. * ''"\v"'' (ASCII 11 (0x0B)), a vertical tab. Notably missing from this list is ''"\f"'' (ASCII 12 (0x0C)), the **Form Feed** character. This RFC proposes adding ''"\f"'' to the default list of characters stripped by ''trim()'', ''ltrim()'', and ''rtrim()''. ===== Proposal ===== The proposal is to include the Form Feed character (''\f'' / ''0x0C'') in the default character mask for ''trim()'', ''ltrim()'', and ''rtrim()''. Most modern programming languages treat ''\f'' as whitespace in their trimming functions. Aligning PHP with this behavior reduces cognitive load for developers working in polyglot environments. The Form Feed character is widely recognized as whitespace. * **C Standard / POSIX:** The ''isspace()'' function in ''libc'' (which PHP relies on internally) defines ''\f'' as a whitespace character. * **PHP Internals:** Other PHP functions such as ''is_numeric()'' already treat ''\f'' as whitespace when parsing strings. * **Python:** ''str.strip()'' removes ''\f'' by default (defined in [[https://docs.python.org/3/library/string.html#string.whitespace|string.whitespace]]). * **JavaScript:** ''String.prototype.trim()'' removes ''\f'' (defined as ''White_Space'' in ECMA-262, see [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim|MDN Web Docs]]). * **Rust:** ''str::trim()'' removes ''\f'' (based on Unicode ''White_Space'' property, see [[https://doc.rust-lang.org/std/primitive.str.html#method.trim|std::primitive::str::trim]]). * **Go:** ''strings.TrimSpace()'' removes ''\f'' (see [[https://pkg.go.dev/strings#TrimSpace|strings.TrimSpace]]). ==== Examples ==== // Current Behavior $str = "\fHello World\f"; var_dump(trim($str)); // string(13) "\fHello World\f" // Proposed Behavior $str = "\fHello World\f"; var_dump(trim($str)); // string(11) "Hello World" ===== Backward Incompatible Changes ===== Scripts that rely on ''trim()'' //preserving// leading or trailing Form Feed characters will be affected. ===== Proposed PHP Version ===== PHP 8.6 ===== Patches and Tests ===== * **Pull Request:** [[https://github.com/php/php-src/pull/20788|GH-20788]] * **Issue:** [[https://github.com/php/php-src/issues/20783|GH-20783]] ===== References ===== * [[https://news-web.php.net/php.internals/129706|Internal discussion]]