← Retour au blog
tech 24 May 2026

PHP's Oddities

PHP is often misunderstood despite its maturity and popularity. Let's explore the oddities of its arrays and type system that challenge developers.

Introduction

PHP, a cornerstone of web development since the 90s, carries a mixed reputation among developers. Often accused of encouraging dubious practices, PHP has evolved over the years to become a versatile and modern language. Yet, some oddities remain and can surprise even the most seasoned developers. This article explores two such oddities: PHP's arrays and its type system.

Arrays: An Unexpected Swiss Army Knife

In PHP, arrays are presented as a unique data structure meant to cover a multitude of use cases. But don't be fooled; what PHP calls an "array" is actually an ordered key-value dictionary. This flexibility comes at a cost: increased complexity.

Take a simple example. You define a fruits array:

``php $fruits = ["apples", "oranges", "limes"]; ``

Everything seems normal until you start manipulating this array. Apply a filter function:

``php $filteredFruits = array_filter($fruits, fn ($name) => str_contains($name, "limes")); print_r($filteredFruits); ``

The output?

`` Array ( [2] => limes ) ``

And now, you have an array with non-sequential keys. Accessing the first element with $filteredFruits[0] won't work.

The Type System: A Puzzle

PHP is a loosely typed language, meaning variable types are implicit and can change dynamically. This makes the language accessible but also prone to subtle errors.

Consider this example:

```php function add($a, $b) { return $a + $b; }

echo add("3 apples", 2); // Result: 5 ```

PHP implicitly converts "3 apples" to 3, ignoring the string part. This can lead to unexpected results and must be managed carefully, especially in critical applications.

Conclusion

PHP has its flaws, but it is also its flexibility that makes it so popular. For developers, it is crucial to understand these oddities and manage them correctly. The good news? Recent PHP versions, notably PHP 8, introduce significant improvements such as strict typing and typed properties, narrowing the gap between PHP and other modern languages.

Let's discuss your project in 15 minutes.

PHP arrays type system web development programming
Deepthix newsletter · 100% AI · every Monday 8am

An AI agent reads tech for you.

Our AI agent scans ~200 sources per week and ships the best articles to your inbox Monday 8am. Free. One click to unsubscribe.

Visit the newsletter page →

Want to automate your operations?

Let's talk about your project in 15 minutes.

Book a call