The Reason For The Weird PHP Function Names
Written by Ian Elliot   
Friday, 27 December 2013

This could just as well be in the humour section. Do you know why PHP has such strange legacy function names? You might be more than surprised when you find out...


PHP Manual Master Pieces is a web site that lists

"Sparkling gems found in the official PHP documentation"

It is a really good read, but only if you are into PHP and some of the wonderful suggestions found in the PHP documentation and the user submitted comments in particular. 

Although it is of interest to mainly PHP programmers, a recent post has enough shock value to be spread to a wider audience who can either feel sorry for the PHP-ers or can laugh themselves silly in a bath of schadenfreude. 

The post on the PHP documentation php.internals forum starts with an innocent enough question. Why are the PHP functions not named using a consistent style that makes them, if not logical, much more regular? The answer supplied is a little bit of PHP history:

"Well, there were other factors in play there. htmlspecialchars was a very early function. Back when PHP had less than 100 functions and the function hashing mechanism was strlen(). In order to get a nice hash distribution of function names across the various function name lengths names were picked specifically to make them fit into a specific length bucket. This was circa late 1994 when PHP was a tool just for my own personal use and I wasn't too worried about not being able to remember the few function names."

OK, you might not have followed what is going on. It isn't so much obscure as unbelievable. Most languages use a hash table to store symbols and this is fairly standard, but in the early days PHP had few functions and just to get things to work the hash function used was string length. Yes, that is correct. All of the functions with the same number of characters in their name were hashed to the same storage location. So obviously to make the system more efficient the function names had to be picked to ensure that the hash function scattered them evenly over the storage - to be 100% clear this means that function names weren't chosen on the grounds of clarity or for consistency of style but to ensure a good distribution of string lengths. 

This is a case of the hash function wagging the data....

Of course this was 20 years ago and no language designer or implementer in their right mind would use such a poor hash function and then arrange for the data to turn it into a good hash function at the expense of linguistic clarity - or would they? 

My guess is that our mistakes grow more subtle over time. 



More Information

PHP Manual Masterpieces

PHP Internals

Related Articles

New - PhpStorm 7       

HipHop VM - Facebook's PHP Virtual Machine    

PHP 5.5.0 Released       


Zend Optimizer+ For PHP?


PHP 5.5 Beta1 Released        


Zend Survey of PHP Developers       


To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.



raspberry pi books



or email your comment to:



Google Season Of Docs 2024 Announced

This year's Google Season of Docs has been announced, and as usual will provide direct grants to open source projects to improve their documentation and give professional technical writers an opportun [ ... ]

Apple - Master Of Malicious Compliance

Apple is under pressure to open up its closed eco system, but it still has the power to resist. It is difficult to force a horse to drink and it is turning out very difficult to make Apple comply with [ ... ]

More News





Last Updated ( Friday, 27 December 2013 )