PHP loves its arrays. Arrays are the uber-data structure. They’re a list, a map, a stack, a queue, everything in one! Which is the problem.

Modern PHP grossly over-uses arrays. In most cases there are better options today, and when you find yourself reaching for “oh I’ll just make this an associative array”, stop. An extra 60 seconds of thought and code will often give you a more readable, faster, more memory-efficient, more flexible alternative. Classes, iterables, and collections can and should replace arrays in most of your day to day coding.

This talk will go through what PHP arrays actually are (hint: they are not, in fact, arrays at all), why they’re so problematic, and what to do instead. By the end, you should find yourself (almost) never reaching for arrays to solve a problem.

Comments

Comments are closed.

Jos Elstgeest at 17:16 on 24 Jan 2020

You've sold me on no longer using array (or at least as little as possible), well presented and argued.
Thank you for sharing your insights and examples.

Koen Cornelis at 23:38 on 24 Jan 2020

Good talk, good examples, well argued.

Steve Winter at 08:07 on 25 Jan 2020

Clear, concise, well explained and with great code examples to back up the explanations.

Good talk. I really liked the generator-based collections.

Good example, nice talk!

Derek Binkley at 12:58 on 25 Jan 2020

Larry made a good argument for becoming less reliant on arrays in PHP. He then gave very good alternatives that are easy to implement.

I love talks which change the way I do certain things. This is one of those talks. Every php dev just needs to see this once to help write better code.

tamar peled at 14:20 on 25 Jan 2020

Great talk! Loved the arguments and the examples. Thank you !

Great talk, great example code. I will keep this in my mind next time I create an array... and decide not to.

Daan at 09:42 on 26 Jan 2020

Larry is an absolute fantastic speaker, i attended both of his talks here.
He made clear arguments against using arrays in *most* places. I was definitely convinced and I know that many others were as well. Thanks, Larry!

Great talk well delivered. Good examples, and engaging way of speaking. There's no wonder I keep bumping into you at conferences, you're such an awesome speaker! Keep this up. *hugs*

What more can I add that has not been said yet? Not much I think.

Great speaker with a very interesting topic.
It gave me a great insight that I can take to my projects.

Well done!

Gifted speaker and able to deliver his points spot on. This talk inspires me to think a lot harder before using those pesky arrays (which I already tried avoiding) and now I have the proof that confirms I was right all along. Thank you.

This was one of my favorite talks on this conference. Very talented speaker combined with a very interesting topic! :)

Niels C at 09:42 on 27 Jan 2020

I feared this talk might just explain how to implement set, stack, queue and some other data types, but it was way better and provided some solid arguments to do things differently. Using generators was the key take-a-way for me.

Great examples of how you should structure your code without the use of associative arrays. Nicely done!

This is one of those rare talks that are just on a league of their own: brilliant, practical insights that think "out of the box"; backed by actual benchmarks; delivered nearly flawlessly with humility and tact. All of that came together to what I consider the most transcendental talk at PHPBenelux 2020. Hat's off.

Timo Schinkel at 20:40 on 1 Feb 2020

I really liked the on point examples. I would have liked a little bit more consistency in the examples; in the first half you mentioned immutability and getters, in the second half this was omitted.

I think it was a great talk. It was very clear that you knew this topic in-depth and that you could argue convincingly for it.
Thank you for the new insights, I will certainly try to use them.

This talk might've been just a little bit difficult to follow for me, though.
Reading your other reviews, that is probably because I'm not as experienced in PHP yet, and not because of your talk itself.

Should you be interested, this is what I think would make it more useful/usable to me.

If you have a little more pause in between the different points of your argument, that can be like a breath of air. It enables me to actually process and store what you've said, before moving along to the next point.

Also, I've noticed you used some "It was easy to do, it took me less than five minutes to code." I feel that you've probably mentioned this to make the patterns you use instead of arrays more accessible to people, and to convince us we should use them. For me, I wasn't done reading your code example yet when you've mentioned that. I didn't really understand yet what was happening, and so that comment had the exact opposite effect on me. It made it less accessible, and more scary to use. Because now, if I will try and use it, and won't think it is as easy, I will feel inadequate. I don't think that's your job to deal with, it's mine. However, using the "This is so easy" argument in a talk almost always distracts me from the actual point of the talk, even if I'm very familiar with the subject and can follow along easily.