
PHP functions originally bucketed by strlen, were renamed to balance length - mappu
http://news.php.net/php.internals/70691
======
mikeash
The site is extremely slow at the moment. In case anyone has trouble accessing
it, I managed to load it, and here's the relevant bit:

    
    
        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.

~~~
tptacek
That can't possibly be true. I refuse to believe it.

~~~
zaphar
Oh It makes complete and total sense. PHP was not a "language" originally. It
was a collection of handy functions in Rasmus' toolbox. When it "graduated" to
language, and I use that term loosely no one bothered to clean it up. No one
bothered to clean it up is PHP's mantra and it explains everything that people
hate about the language perfectly.

~~~
MichaelGG
Even with the "PHP is a personal hack", it doesn't make sense. More effort
goes into naming functions than writing a one-line xor "hash".

I'm more inclined to believe Rasmus is trolling here. Sure, he used strlen,
but it's too hard to believe functions were named with this in mind.

~~~
ma2rten
I think the point is that it is simple to add symbols in the C source code.
You simply count the number of characters and then add it in the appropriate
place.

------
mistercow
Sometimes I feel like Rasmus Lerdorf is going to come clean one bright April
Fools' Day, and reveal that PHP was just a hilarious joke that sort of got out
of hand.

~~~
jtreminio
Yeah! Haha the joke's on Facebook, Wikipedia, Flickr, Yahoo! Answers,
Photobucket, Digg (RIP), etc ... Those fools have been using a joke language
and didn't even know it!

Seriously, the PHP hate gets old. It started off very much as a scratch to one
man's itch. That man wasn't the best programmer ever (wouldn't even say top
10%, or even close), but he had an idea and executed it to make one of the
most successful free products ever that has generated billions and billions of
dollars for the world economy.

Can you say the same?

~~~
mehwoot
_that has generated billions and billions of dollars for the world economy._

That's an interesting thought. Has it? I wonder what a lot of websites would
have used if PHP has not been around. I wonder if, overall, PHP existing has
actually generated billions and billions of dollars in value.

~~~
protomyth
Not sure what they would have used because it seems like no other language
makes it quite as easy to install and start using. I get the feeling a lot of
language designers don't really get that some poor sap has to get the language
installed on the web server.

~~~
felipellrocha
Any of the myriad of good languages available out there? Php is only easy to
install because it comes pre-installed in most low-end servers out there.
Without that fact, php is just as cumbersome to get started as any other
language.

~~~
Killswitch

        sudo apt-get install apache2 php5 libapache2-mod-php5
    

Boom, I just installed PHP5 on Apache on Ubuntu, now I just upload a file to
my project root.

Let me know when you find any way easier than that.

~~~
felipellrocha
Meanwhile, Python comes already installed by default in most linux
distributions. So, forget .ini files, forget apache until deployment
time(hell, don't be forced onto apache if you don't want to. Choose
_whichever_ deployment server you want. I know... options... it's weird...
you'll get used to it), forget worrying about php upgrades on shared machines,
forget that apt-get line. .py file, and you're up and running (and headache-
less).

~~~
emilv
I have a fresh install of such a distro, where Python is included. What do I
need to do to from Python present an input form which takes my name and a
second page that greets me using the same name? Including deployment of
course, how else should I test it without paying a web host?

I'm not discussing headaches, I do nit particularly like PHP. My point is just
that Python is not very easy to get started with for beginners.

~~~
Shish2k

      import web
              
      urls = (
          '/(.*)', 'hello'
      )
      app = web.application(urls, globals())
      
      class hello:        
          def GET(self, name):
              if name: 
                  return 'Hello, ' + name + '!'
              else:
                  return "<form><input name='name'></form>"
      
      if __name__ == "__main__":
          app.run()
    

upload into your web server's cgi-bin folder, or have the server configured to
exec all *.py files as python

ED> yeah, this is a few more lines of code than PHP and it requires a teeny
tiny amount of knowledge about how the web works - and that "takes 5 minutes
to get started" vs PHP's "takes 2 minutes to get started" is a big difference
for someone who doesn't know what they're doing but wants results immediately
:P

EDED> Actually now that I think about it, that's how /I'd/ start a simple
webapp as it has the structure in place to grow easily and elegantly -- if
you're willing to do things the quick and dirty way, you can go without a
framework and just print an HTTP response to stdout - in which case the only
difference with PHP is that the python version requires "print 'Content-type:
text/html\n'" at the top

~~~
emilv
I certainly do agree that this somewhat more abstract approach is much better
for stable web applications. My point is that PHP doesn't require you to
understand anything to get started, which explains its widespread usage. That
is of course not true if you want security or maintainability, but that is
exactly the snake oil sold by PHP.

But this web framework is much newer than PHP, isn't it? And this does not
look better or easier than PHP:
[https://wiki.python.org/moin/CgiScripts](https://wiki.python.org/moin/CgiScripts)

~~~
Shish2k
> And this does not look better or easier than PHP:
> [https://wiki.python.org/moin/CgiScripts](https://wiki.python.org/moin/CgiScripts)

That has tracebacks on error and HTML escaping, so I'd say it's considerably
better for a tiny increase in difficulty (but you're right that no matter now
tiny the difference, PHP is still easier)

------
girvo
I've always wondered if there was a place for a language that was properly
designed, but copied PHP/php-fpm's execution model? It has beautiful
horizontal scaling, but perhaps the long lived process model is better (ruby,
go, etc) than PHP's "stateless" (as in, the app holds no real state itself
after the request, it shuts down) per-req setup. Thoughts?

~~~
igul222
See CGI.

~~~
girvo
Actually, I've been looking at SCGI with Nimrod... ;)

Seriously though, I've been trying to find out lately whether CGI is at all
useful in this day and age, or whether if some well-designed scripting
language that used the PHP style of run-time would be better to avoid using
it.

There's not much info on CGI/SCGI in 2013 :'(

------
kabdib
I've written a few thousand lines of PHP in the last year or so. Every time I
do, I want to weep.

It might be better than Perl, but not by much.

~~~
smacktoward
Like Perl, PHP is a long-lived, heavily-used-in-production language, which
means there is a lot of cruft that has accumulated over the years that's
difficult for the platform developers to just slough off. But much like there
is a Modern Perl movement that has coalesced around _voluntarily_ cutting out
cruft and using a much cleaner, nicer-to-work-width subset of Perl, there is a
similar movement in PHP-land that's doing the same thing.

PHP The Right Way
([http://www.phptherightway.com/](http://www.phptherightway.com/)) is a good
place to start if you're curious what "modern PHP" looks like.

~~~
Killswitch
This. Nobody taken seriously in PHP world doesn't use modern PHP tools, Good
frameworks, Composer, follow PHP-FIG standards, all that stuff... Just because
you had to maintain a PHP4 app 10 years ago, doesn't mean PHP hasn't changed.
And it also doesn't mean real devs don't have standards and follow up-to-date
guidelines.

~~~
aaronbrethorst
I'm guessing you haven't spent that much time looking at the Wordpress
ecosystem...there's some truly heinous stuff in there.

~~~
benwerd
For sure. WordPress has a lot of legacy backwards compatibility on its
shoulders. If they could shrug it off and start again, I'm sure it would be a
lot cleaner.

The project I'm working on
([https://github.com/idno/idno](https://github.com/idno/idno)) is PHP, but
explicitly doesn't support legacy versions, in order to rule out the way of
working that was finally made obsolete in v5.3. I'm very happy with the
language, and I can usually express what I need simply. Reflection could use a
little love, mind you.

~~~
girvo
I'm building some projects that are only targeted at 5.5 -- once you do that,
and stick to all the PSR standards, then it's actually really nice, super
productive, and the cruft that exists gets ignored. I like PHP still _shrugs_

------
fprawn
There's a lesson here about how sometimes it's okay to fit your data to your
code. This was, afterall, in php for years without causing much, if any,
problems for end users.

I guess there won't be much agreement here on HN, but this deserves to be
recognized as an amusing and clever solution to a problem. Even if the problem
is self created.

PHP is great for doing quick and dirty dynamic web pages. So what if it
doesn't scale out to a million line program?

~~~
RobAley
> PHP is great for doing quick and dirty dynamic web pages.

And a lot more besides (subtle plug for
[http://www.phpbeyondtheweb.com](http://www.phpbeyondtheweb.com) )

> So what if it doesn't scale out to a million line program

I've seen more that one PHP codebase of that size, happily (and maintainably)
plodding along.

------
jamesbrennan
Is the PHP source from 1994 available anywhere? That would help determine if
this is Rasmus's satire or not.

~~~
abimaelmartell
[http://museum.php.net/php1/](http://museum.php.net/php1/)

~~~
snyff
from php-2.0.1/src/lex.c

void IntFunc(char *fnc_name) { int i=0; int cmdlen = strlen(fnc_name);

    
    
      while(cmd_table[cmdlen][i].cmd) {
        if(!strncasecmp(fnc_name,cmd_table[cmdlen][i].cmd,cmdlen)) {
          cmd_table[cmdlen][i].fnc();
          break;

------
djmdjm
It's amazing that, after all these years, PHP still has the ability to horrify
me.

Hello again, old friend.

------
skloubkov
While I understand why this was done (for the sake of comparability), I feel
like its better to bite a bullet and slowly phase out broken functions over
several versions.

Warn initially (few versions) and then raise exception/critical errors after.
If developer isn't willing to update, chances are server isnt being updated
either anyways.

~~~
shoyer
Better idea: bite the bullet, drop PHP. Switch to a language that was
designed. In the eyes of many of us, PHP is beyond redemption.

~~~
Killswitch
Better idea: Be a better programmer and don't blame a language because you
suck.

~~~
prodigal_erik
No amount of "being a better programmer" can fix the fact that $x == $y && $y
== $z does not guarantee that $x == $z or $a[$x] == $a[$y]. Nor that passing
by value may or may not protect you from destructive updates, depending on
whether _your caller_ passed by reference. The language simply can't be
trusted to behave predictably; a huge number of its features have some kind of
trap built in by mistake.

~~~
jl6
Is there actually something non-deterministic about PHP? If not it seems like
a better programmer would simply be aware of the language's less elegant
features and work around them.

~~~
awestroke
So, PHP is a good tool because a 'better' programmer can make good things
DESPITE using PHP?

~~~
jl6
Who said PHP was a good tool? I'm responding to the parent comment asserting
that being a better programmer won't help you, which is clearly not true. All
our tools are deficient to a greater or lesser extent, and part of what
defines the skill of a programmer is working with the tools you have, working
around their deficiencies, and resisting the urge to engage in architecture
astronautism.

If you have a choice, sure, don't use PHP. But if you don't have a choice, PHP
won't stop you shipping a quality product.

------
Tloewald
Well, points for honesty, I guess.

------
ibudiallo
Ok i will admit it, i didn't understand a thing. Would someone care to explain
it to me?

~~~
dsego
I'm not really sure if this is right, but my best guess is that script parsers
use a hash table to map the name of a function to a function pointer or
something. Hash tables enable fast information retrieval by some key (usually
a string). By just knowing the key you immediately (or after some
calculations) know in which bucket to search for the element. For details see
[http://en.wikipedia.org/wiki/Hash_table](http://en.wikipedia.org/wiki/Hash_table).

For the hash table to be efficient, an algorithm that stores the elements has
to evenly distribute them across the buckets. But instead of using a "proper"
algorithm, a string length was used to determine in which bucket a function
name belongs. To have the names evenly distributed, the names had to be of
different lengths, even if that meant abandoning some naming conventions.

------
dsego
Fu*k it, ship it?

