Based on the official PHP documentation, the metaphone() function in PHP 8.5 is identical to previous versions; no new changes or features specific to PHP 8.5 have been introduced for this function.
Function Signature and Behavior
metaphone(string $string, int $max_phonemes = 0): string
- Purpose: Generates a Metaphone key for a string (based on English pronunciation rules). Words with similar pronunciation will produce the same key, making it more accurate than soundex().
- $max_phonemes Parameter: Limits the maximum length of the returned key (default 0 means no limit). Note that phonemes are always transcribed as a whole, so the final returned string may be slightly longer than the specified length (e.g., Asterix with a limit of 5 returns ASTRKS with length 6).
- Return Value: Returns the Metaphone key as a string. Starting from PHP 8.0, failure returns false (previously returned false as well, but the type declaration was more explicit).
Basic Examples
var_dump(metaphone( programming )); // string(7) "PRKRMNK"
var_dump(metaphone( programmer )); // string(6) "PRKRMR"
var_dump(metaphone( programming , 5)); // string(5) "PRKRM"
Important Notes (Security/Stability)
In versions prior to 8.5.6, passing extremely long strings (exceeding 2,147,483,647 bytes) to metaphone() may trigger a signed integer overflow, leading to out-of-bounds reads, which can cause a segmentation fault and affect process availability. It is recommended to keep the PHP 8.5 patch version up to date to avoid this issue.