# PHP: Frankenstein arrays

**URL:** <https://forum.devtalk.com/t/php-frankenstein-arrays/37479>\
**Category:** Backend In The News\
**Tags:** php\
**Created:** [22 January 2022 15:52 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479 "2022-01-22T15:52:38Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![CommunityNews](https://forum.devtalk.com/user_avatar/forum.devtalk.com/communitynews/32/1113_2.png) [@CommunityNews](https://forum.devtalk.com/u/CommunityNews)\
**Post date:** [22 January 2022 15:52 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/1 "2022-01-22T15:52:38Z")

</div>

> PHP: Frankenstein arrays.  
> PHP has become quite a nice language, but there are some ugly legacies left from the past. Like the deceptive Frankenstein abomination known as the “array”.

Read in full here:

> **[PHP: Frankenstein arrays](https://vazaha.blog/en/9/php-frankenstein-arrays)**
>
> PHP has become quite a nice language, but there are some ugly legacies left from the past. Like the deceptive Frankenstein abomination known as the "array".

_This thread was posted by one of our members via one of our news source trackers._

---

<div class="post-metadata">

**Author:** ![mindriot](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mindriot/32/6660_2.png) [@mindriot](https://forum.devtalk.com/u/mindriot)\
**Post date:** [22 January 2022 21:17 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/3 "2022-01-22T21:17:04Z")

</div>

This seems to rear its ugly head pretty often when having to deal with a JSON API. Had to deal with this a few times recently. Discovered the other week, if you give it a JSON object with only numeric keys (which are strings with numbers in them because numbers as keys are not valid JSON) regardless of whether they are sequential, it thinks the object is an array. Who would have thought `{“1”; “one”, “9”: “nine”}` should be turned into `[“one”, “nine”]`? 🤷‍♂️ apparently someone

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.devtalk.com/user_avatar/forum.devtalk.com/overminddl1/32/52_2.png) [@OvermindDL1](https://forum.devtalk.com/u/OvermindDL1)\
**Post date:** [24 January 2022 17:55 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/4 "2022-01-24T17:55:56Z")

</div>

PHP has some very interesting oddities, but is it more or less than JS’s very weird oddities, lol…

---

<div class="post-metadata">

**Author:** ![mindriot](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mindriot/32/6660_2.png) [@mindriot](https://forum.devtalk.com/u/mindriot)\
**Post date:** [25 January 2022 15:41 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/5 "2022-01-25T15:41:45Z")

</div>

I’m not sure if it is more or less, JS weirdness I’m much more familiar with which doesn’t make it particularly easy to look at objectively. I do tend to find that while JS has a lot that is really easy to poke fun at, it is also generally fairly easy to avoid (within the bounds of a complete lack of type safety) many of the pitfalls. I also generally find a lot of discussion, examples of usage etc go a long way to pushing you away from those pitfalls as well. Laravel by default decodes JSON in this way, so with what is one of the most popular web frameworks you are basically being guided towards having this problem and certainly on the versions I’ve had to deal with recently (which are old) there is no easy way to get at the original request in the middleware chain or the validation rules they have, making things impacted by this decision painful to do validation on. Also today I learned in another case of PHP weirdness that the string “0” is falsey, so

```auto
if(“0”) {
    // do nothing
} else { 
    echo “wat!”; 
}

```

Does indeed echo “wat!”. Even JS isn’t quite that insane unless you introduce some coercion into the condition (at which point you will receive all the pain and suffering that comes with doing something so stupid).

---

<div class="post-metadata">

**Author:** ![adamaiken89](https://forum.devtalk.com/user_avatar/forum.devtalk.com/adamaiken89/32/2661_2.png) [@adamaiken89](https://forum.devtalk.com/u/adamaiken89)\
**Post date:** [31 January 2022 01:07 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/6 "2022-01-31T01:07:07Z")

</div>

> [@OvermindDL1](#):
>
> PHP has some very interesting oddities, but is it more or less than JS’s very weird oddities, lol

The issues of PHP were because there was a standard as C wrapper and PHP own standards.  
Also, the ways of patching PHP in the early versions…

JS is a totally different case. In the early years, each browser implements its own feature without comparing the style…

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.devtalk.com/user_avatar/forum.devtalk.com/overminddl1/32/52_2.png) [@OvermindDL1](https://forum.devtalk.com/u/OvermindDL1)\
**Post date:** [2 February 2022 16:26 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/7 "2022-02-02T16:26:44Z")

</div>

> [@adamaiken89](#):
>
> The issues of PHP were because there was a standard as C wrapper and PHP own standards.  
> Also, the ways of patching PHP in the early versions…

Oh I don’t even mean the exceptionally odd and inconsistent standard library functions, I mean as a language, most of the issues coming down to annoying dynamic typing.

---

<div class="post-metadata">

**Author:** ![dimitarvp](https://forum.devtalk.com/user_avatar/forum.devtalk.com/dimitarvp/32/5599_2.png) [@dimitarvp](https://forum.devtalk.com/u/dimitarvp)\
**Post date:** [7 February 2022 19:56 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/8 "2022-02-07T19:56:21Z")

</div>

PHP: the gift that keeps on giving.

And to think there are people furiously defending it to this day…

---

<div class="post-metadata">

**Author:** ![mindriot](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mindriot/32/6660_2.png) [@mindriot](https://forum.devtalk.com/u/mindriot)\
**Post date:** [7 February 2022 21:02 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/9 "2022-02-07T21:02:48Z")

</div>

Today I read some of this comment thread on hacker news, boggles the mind [PHP – The Right Way | Hacker News](https://news.ycombinator.com/item?id=30219984)

---

<div class="post-metadata">

**Author:** ![dimitarvp](https://forum.devtalk.com/user_avatar/forum.devtalk.com/dimitarvp/32/5599_2.png) [@dimitarvp](https://forum.devtalk.com/u/dimitarvp)\
**Post date:** [7 February 2022 21:07 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/10 "2022-02-07T21:07:42Z")

</div>

To be fair, I lost patience reading such threads. They usually boil down to:

“If you are a disciplined hardcore veteran like myself you’ll never make these mistakes!”

Which is so dumb and unrealistic that it should not even be graced with the honor of replying to it.

---

<div class="post-metadata">

**Author:** ![mindriot](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mindriot/32/6660_2.png) [@mindriot](https://forum.devtalk.com/u/mindriot)\
**Post date:** [7 February 2022 21:21 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/11 "2022-02-07T21:21:56Z")

</div>

There is a bit of that, there are a bunch of different points from different perspectives in there, but there are a surprising amount of people attempting to make serious arguments that PHP is a better choice than python or ruby, or generally most dynamic languages

---

<div class="post-metadata">

**Author:** ![dimitarvp](https://forum.devtalk.com/user_avatar/forum.devtalk.com/dimitarvp/32/5599_2.png) [@dimitarvp](https://forum.devtalk.com/u/dimitarvp)\
**Post date:** [7 February 2022 21:39 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/12 "2022-02-07T21:39:50Z")

</div>

Sunk cost fallacy. 🤷

I was 40 years old when I realized, for the first time in my life, that me willing to throw away acquired skills and moving to gain new ones, is an aberration and not the norm.

Most people learn a few things and hold onto them with a death grip.

I actually met a woman last year who was LOUDLY BRAGGING about knowing how to manage a Blogger page/blog and was asking me how can she reuse that knowledge if she were to learn how to do so for WordPress and Magento websites… A valid question, surely, but she was just hell-bent on learning the minimum possible amount and that really stood out to me.

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.devtalk.com/user_avatar/forum.devtalk.com/overminddl1/32/52_2.png) [@OvermindDL1](https://forum.devtalk.com/u/OvermindDL1)\
**Post date:** [7 February 2022 22:22 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/13 "2022-02-07T22:22:35Z")

</div>

> [@dimitarvp](#):
>
> “If you are a disciplined hardcore veteran like myself you’ll never make these mistakes!”

Sounds like the reason some people to use C over Rust… \>.\>

The point of the extra features rust has isn’t for convenience in immediate programming, it’s to catch errors that _EVERYONE_, including the “grizzled veteran” (even if less often) makes.

PHP is on the level of C, it’s very low level, easy to break, no good early catches, etc…

---

<div class="post-metadata">

**Author:** ![mindriot](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mindriot/32/6660_2.png) [@mindriot](https://forum.devtalk.com/u/mindriot)\
**Post date:** [7 February 2022 23:05 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/14 "2022-02-07T23:05:44Z")

</div>

> [@OvermindDL1](#):
>
> Sounds like the reason some people to use C over Rust… \>.\>
> 
> The point of the extra features rust has isn’t for convenience in immediate programming, it’s to catch errors that _EVERYONE_, including the “grizzled veteran” (even if less often) makes.

The one that gets me is Go, it is creating something new that is an active rejection of everything anyone has learned since C. Though that doesn’t really relate to PHP at all, it does seem to suffer a lot from the idea that if you just do it right then it won’t be a total disaster.

---

<div class="post-metadata">

**Author:** ![dimitarvp](https://forum.devtalk.com/user_avatar/forum.devtalk.com/dimitarvp/32/5599_2.png) [@dimitarvp](https://forum.devtalk.com/u/dimitarvp)\
**Post date:** [7 February 2022 23:52 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/15 "2022-02-07T23:52:52Z")

</div>

Well, don’t forget the fact that one of Golang’s creators said they were aiming at fresh college grads with C or Java background…

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.devtalk.com/user_avatar/forum.devtalk.com/overminddl1/32/52_2.png) [@OvermindDL1](https://forum.devtalk.com/u/OvermindDL1)\
**Post date:** [7 February 2022 23:56 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/16 "2022-02-07T23:56:54Z")

</div>

I think the creator of Go had this to say about it:

> The key point here is that our programmers are not researchers. They are, as a rule, very young, they come to us after their studies, perhaps they studied **Java** , **C / C ++** or **Python**. They can’t understand an outstanding language, but at the same time we want them to create good software. That is why their language should be easy for them to understand and learn.
> 
> It should be familiar, roughly similar to **C**. Programmers working at Google start their careers early and are mostly familiar with procedural languages, in particular the **C** family. The demand for speedy productivity in a new programming language means that the language doesn’t have to be too radical.

I still don’t see how golang helps make good software, I keep running into crashes with go programs and libraries… \>.\>

---

<div class="post-metadata">

**Author:** ![dimitarvp](https://forum.devtalk.com/user_avatar/forum.devtalk.com/dimitarvp/32/5599_2.png) [@dimitarvp](https://forum.devtalk.com/u/dimitarvp)\
**Post date:** [8 February 2022 00:09 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/17 "2022-02-08T00:09:07Z")

</div>

Yep. And that was Google’s goal: a fresh stream of new grads to hire and use and throw away any time they need them.

Gotta admire their criminal genius. 🙂

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [8 February 2022 17:38 UTC](https://forum.devtalk.com/t/php-frankenstein-arrays/37479/18 "2022-02-08T17:38:18Z")

</div>

> [@OvermindDL1](#):
>
> > That is why their language should be easy for them to understand and learn.

I totally agree with this, but would also add it should be intuitive and feel natural (so not frustrating) - these are some of the things that makes people want to use a language (some of the others are what you can do with it or the power it affords you) 😃
