PHP's Oddities
4 days ago
- #Array behavior
- #PHP quirks
- #Type system
- PHP often receives criticism based on outdated perceptions; modern versions are versatile and feature-rich.
- PHP's arrays are actually ordered key-value dictionaries, which can lead to unexpected behavior during mutations like sorting or filtering.
- Using functions such as array_filter() or unset() can disrupt array indices, requiring array_values() to reset them.
- Class property types in PHP introduce an 'uninitialized' state distinct from NULL, causing fatal errors if accessed before initialization.
- Untyped properties default to NULL, but typed properties (including nullable ones) remain uninitialized by default unless explicitly set.
- The type system's quirks, combined with dynamic property addition, complicate defensive coding and object structure clarity.
- Despite its quirks, PHP offers low development friction, effective frameworks like Laravel, and remains capable for various tasks.