Live data from Hacker News

PHP 7's new hashtable implementation

nikic.github.io

21–30 of 137 posts

Re: PHP 7's new hashtable implementation

#22
post #14
post #7

This is great news. PHP doesn't have many structured data types, so arrays (aka maps) are basically used for everything. Any improvement to them will impact the entire application. It would be nice to have separate types for arrays and maps though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now.

PHP has a standard library with plenty of collections: http://php.net/manual/en/book.spl.php Stack - http://php.net/manual/en/book.spl.php Queue - http://php.net/manual/en/class.splqueue.php PriorityQueue - http://php.net/manual/en/class.splpriorityqueue.php Real Maps - http://php.net/manual/en/class.splobjectstorage.php It's a shame some people are not aware of these.

Well, yeah, I agree that the SPL types are nice to have. My complaint is that PHP's only first-class array type is a weird array/map combo. Have you ever seen anything like that in another language?

The SPL types are definitely a welcome addition to the language, but they feel like add-ons. Definitely not first-class. The standard array functions don't work with SPL types (array_map, etc.) even though the SPL types are iterable.

More to my point, missing from SPL is a dynamically-sized array that's not based on linked lists. Linked lists don't have O(1) lookup. This type of array really should be first-class, but it’s completely missing from the language. Please correct me if I’m overlooking something!

That said, I believe having separate, first-class, dynamic arrays and maps would strike a better balance of dynamism, performance, and predictability compared to the single existing first-class array/map.

Re: PHP 7's new hashtable implementation

#23
It is both nice and concerning, that an ubiquitous element of a ubiquitous language has that much potential for performance optimizations after 19 years of development. The optimizations were not even complicated hacks for edge cases, just a simpler implementation overall.

But then again, PHP itself being stateless between requests is quite fast already, nice to see even more performance getting squeezed out. Imagine the decrease in global energy consumption due to this change. :D

Re: PHP 7's new hashtable implementation

#24
post #22
post #14

Earlier quoted context omitted.

PHP has a standard library with plenty of collections: http://php.net/manual/en/book.spl.php Stack - http://php.net/manual/en/book.spl.php Queue - http://php.net/manual/en/class.splqueue.php PriorityQueue - http://php.net/manual/en/class.splpriorityqueue.php Real Maps - http://php.net/manual/en/class.splobjectstorage.php It's a shame some people are not aware of these.

Well, yeah, I agree that the SPL types are nice to have. My complaint is that PHP's only first-class array type is a weird array/map combo. Have you ever seen anything like that in another language? The SPL types are definitely a welcome addition to the language, but they feel like add-ons. Definitely not first-class. The standard array functions don't work with SPL types (array_map, etc.) even though the SPL types a…

Lua also have hybrid array, maps and object. It does work well when implemented in a sane way. Lua has different way of iterating the table if you want an array or maps.

Re: PHP 7's new hashtable implementation

#25
post #22
post #14

Earlier quoted context omitted.

PHP has a standard library with plenty of collections: http://php.net/manual/en/book.spl.php Stack - http://php.net/manual/en/book.spl.php Queue - http://php.net/manual/en/class.splqueue.php PriorityQueue - http://php.net/manual/en/class.splpriorityqueue.php Real Maps - http://php.net/manual/en/class.splobjectstorage.php It's a shame some people are not aware of these.

Well, yeah, I agree that the SPL types are nice to have. My complaint is that PHP's only first-class array type is a weird array/map combo. Have you ever seen anything like that in another language? The SPL types are definitely a welcome addition to the language, but they feel like add-ons. Definitely not first-class. The standard array functions don't work with SPL types (array_map, etc.) even though the SPL types a…

> My complaint is that PHP's only first-class array type is a weird array/map combo. Have you ever seen anything like that in another language?

Um, Javascript?

Re: PHP 7's new hashtable implementation

#27
post #7

This is great news. PHP doesn't have many structured data types, so arrays (aka maps) are basically used for everything. Any improvement to them will impact the entire application. It would be nice to have separate types for arrays and maps though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now.

> arrays (aka maps) are basically used for everything.

This is interesting. In fact, I believe object properties share the same mechanism as associative arrays, that is, $a->b will actually lookup the hash of "b" in $a. Does this new hashtable layout influence object properties/methods too? That would be huge!

Re: PHP 7's new hashtable implementation

#29
post #25
post #22

Earlier quoted context omitted.

Well, yeah, I agree that the SPL types are nice to have. My complaint is that PHP's only first-class array type is a weird array/map combo. Have you ever seen anything like that in another language? The SPL types are definitely a welcome addition to the language, but they feel like add-ons. Definitely not first-class. The standard array functions don't work with SPL types (array_map, etc.) even though the SPL types a…

> My complaint is that PHP's only first-class array type is a weird array/map combo. Have you ever seen anything like that in another language? Um, Javascript?

Javascript's arrays cannot be used as maps or associative arrays. Arrays require numeric, consecutive keys. Otherwise it's an Object.

--

Clarification edit: Creating a new key on an array using arr['key']=1 creates a property on the arr Object but does not add an element to the standard array.

http://stackoverflow.com/questions/8630471/strings-as-keys-o...

Re: PHP 7's new hashtable implementation

#30
post #25

Earlier quoted context omitted.

> My complaint is that PHP's only first-class array type is a weird array/map combo. Have you ever seen anything like that in another language? Um, Javascript?

Javascript's arrays cannot be used as maps or associative arrays. Arrays require numeric, consecutive keys. Otherwise it's an Object. -- Clarification edit: Creating a new key on an array using arr['key']=1 creates a property on the arr Object but does not add an element to the standard array. http://stackoverflow.com/questions/8630471/strings-as-keys-o...

Arrays are always objects in JavaScript, and they can be extended like any other object or used as maps (barring key conflicts).
Post reply on HN