The single best thing about PHP (the language) is the implementation of arrays. In all other similar languages (Perl, Python, Ruby, JavaScript) you always have to make decision:
create normal array, which you can access sequentially, but where you can only use numeric indexes.
create associative array, where you can use non-numeric indexes, but which you can't access sequentially.
In PHP you never have to make this decision -- you just always create an array and depending on how you use it, it will behave as associative array or as sequential array.
If there is anything worth copying from PHP by other languages, then this unification of normal and associative arrays is ceartanly one of those things.
Of course it's not all fun and joy as arrays in PHP eat quite a bit of memory. But from the ease-of-use perspective for the programmer, PHP arrays are pretty damn good.
But although PHP arrays have all those great properties, they are still pain in the ass to use.
Let's look at an example. This is how you declare an array in Perl, Python, Ruby, JavaScript, ML, Haskell and probably in many other languages:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
This is how you do the same in C++ and Java:
{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
And from the historical perspective, here is the same in ALGOL:
((1, 2, 3), (4, 5, 6), (7, 8, 9))
And here we have Lisp, which is famous for it's lack of syntax, but with pretty good semantic sugar for arrays:
'((1 2 3) (4 5 6) (7 8 9))
Compare all these to "the PHP way" of doing things:
array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))
How in the hell did they came up with this syntax???
Probably like Larry Wall put it:
I thought of a way to do it so it must be right.
So is there any hope for this clumsy syntax to change in the future? PHP6 maybe?
Well, I guess no. There was a proposal for alternative short syntax for arrays, but it was voted down.
Like they say on the gate to PHP:
Abandon all hope, ye who enter here.
Kirjutatud 27. juunil 2008.
RSS, RSS kommentaarid, XHTML, CSS, AA
Arvamused ja täiendused
Can anyone explain the "I thought of a way to do it so it must be right" context? Its a satire over something that a PHP creator said?
Seda ütles 14. juulil 2008 kell 16:11 antoniomanteiga.
I guess it just points to the fact, that nobody really designed PHP. Everyone just contributed some functions, they hought were missing, so that the first solution, that somebody came up with, just ended up staying in the language forever.
Seda ütles 17. juulil 2008 kell 20:42 Rene Saarsoo.
Shame there wasn't a way to set your own aliases up for keywords and structures... (There maybe! I haven't done too much research into it). I can understand concerns in doing that... but for internal practices, it would be a useful feature.
Seda ütles 25. jaanuaril 2009 kell 13:48 Richard Healy.
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.
Seda ütles 22. jaanuaril 2012 kell 14:52 System.
Shame there wasn't a way to set your own aliases up for keywords and structures... (There maybe! I haven't done too much research into it). I can understand concerns in doing that... but for internal practices, it would be a useful feature.
Seda ütles 23. jaanuaril 2012 kell 17:08 Küstenpatent Kroatien.
I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement. Thanks for sharing with us.
Seda ütles 25. jaanuaril 2012 kell 15:55 free dumps.
This is a nice blog. Good clean UI and nice informative blog. I will be coming back soon, thanks for the great blog. I put a link to your blog at my site, hope you don't mind?
Seda ütles 27. jaanuaril 2012 kell 17:33 essay service.
Just stumbled across your blog and was instantly amazed with all the useful information that is on it. Great post, just what i was looking for and i am looking forward to reading your other posts soon!
wellwisdom.com
Seda ütles 28. jaanuaril 2012 kell 11:50 wellwisdom.com.
Very helpful, This post gives quality information. You made some exceptional points and I am grateful for your insight!
buy sites
Seda ütles 29. jaanuaril 2012 kell 05:51 buy sites.
Glad to have found the information matching my criteria. This will really help me in completing my work easily and on time. Thanks for sharing.
chicago bears Dog collar
Seda ütles 29. jaanuaril 2012 kell 09:12 chicago bears Dog collar.
This is so cool. I am such a huge fan of their work. I am impressed with how much you have worked to make this website so enjoyable.
seattle plumbers
Seda ütles 29. jaanuaril 2012 kell 11:58 seattle plumbers.
I really find it hard to understand arrays specially when it goes multi-dimensional.
Male Enhancement Reviews|Vimax Pills
Seda ütles 30. jaanuaril 2012 kell 01:46 Esther Folley.
Very informative post. I was looking for information about this topic and this post really helped me a lot. Thanks for sharing.
Seda ütles 30. jaanuaril 2012 kell 17:56 New York Web Design.
Very Useful information, this is both good reading for, have quite a few good key points and I learn some new stuff from it too.
Seda ütles 30. jaanuaril 2012 kell 21:25 kiwi fruit.
Easily, the post is really the sweetest on this worthwhile topic. I fit in with your conclusions and will eagerly look forward to your approaching updates. Saying thank
Seda ütles 31. jaanuaril 2012 kell 15:09 chase credit card.
Excellent and decent post. I have found much informative, what I was exactly searching for. Thanks for such post and please keep it up.
cute babies
Seda ütles 1. veebruaril 2012 kell 11:12 cute babies.
Your site is good Actually, i have seen your post and that was very informative and very entertaining for me. Thanks for posting Such a post. I should recommend your site to my friends. Cheers.
crowd sourcing
Seda ütles 1. veebruaril 2012 kell 13:05 crowd sourcing.
I will be coming back soon, thanks for the great blog. I put a link to your blog at my site, hope you don't mind?A.Lange & Sohne Replica Watches
Seda ütles 2. veebruaril 2012 kell 10:01 kilaer.
I like what you guys are writing about. Keep up the good works guys, I've you to our website.
Seda ütles 2. veebruaril 2012 kell 10:55 how to improve your eyesight.
I am writing a research paper and collecting information on this topic. Your post is one of the better that I have read. Thank you for putting this information into one location.
Seda ütles 2. veebruaril 2012 kell 21:28 dolce & gabbana sunglasses.