|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48709 metaphone and 'wh'
Submitted: 2009-06-28 05:29 UTC Modified: 2009-06-29 03:35 UTC
From: brettz9 at yahoo dot com Assigned: felipe (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.2, 5.3, 6CVS-2009-06-28 (snap) OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: brettz9 at yahoo dot com
New email:
PHP Version: OS:


 [2009-06-28 05:29 UTC] brettz9 at yahoo dot com
The source for metaphone() states in the comments that "WH becomes H" and when one tests it, e.g., with "whit", as per the comment on line 227 and the code which phonizes Next_Letter on line 233 when there is a 'W' followed by 'H', it returns 'H' ("ht" for 'whit'). 

However, according to the metaphone() algorithm (see and the original implementation at ), 'wh' should become 'w', not 'h'.

So, to fix it, you could change the comment on 233 to:

/* WH becomes W, 

and then change the 'if' on 231-234 to:

if (Next_Letter == 'H') {
    w_idx += 2;
} else if (Next_Letter == 'R') {
    w_idx += 2;

Reproduce code:

echo metaphone('Whit');


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-28 18:45 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed in 5.2 and HEAD.
5.3 in soon.

 [2009-06-29 02:50 UTC] brettz9 at yahoo dot com
Although my patch was indeed better than the previous form, I was mistaken in saying that 'wh' should be pronounced as 'w' per the original algorithm (that is only if the 'w' is followed by a vowel).

Although treating 'wh' as 'w' (as you have it now) may indeed be more in the spirit of how metaphone() generally works, if you wish to have fidelity with the original algorithm such as implemented in Basic at (and as implemented on other systems), I think you would need to drop this handling.

So, to follow the original algorithm, it seems to me that the entire case for 'W' should be removed (line 230 in the previous snapshot).

But if you don't care about consistency with other original-based implementations (the Perl one added its own rules, including this one), then my previous patch should be kept.

My apologies for the confusion.
 [2009-06-29 03:32 UTC]
But the initial letter exceptions are treated in the Basic code too.
 [2009-06-29 03:35 UTC] brettz9 at yahoo dot com
Ahh, ok, sorry, failed to check that this time, sorry... (Have a few more patches for metaphone() coming your way, though I'll open a new bug.)
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 05:01:26 2019 UTC