Five Years of PHP: Where Arrays and Type Declarations Still Bite
A developer reflects on half a decade maintaining a PHP backend and zeroes in on two recurring sources of bugs. The first is PHP’s array, which is really an ordered key-value map masquerading as a list. Operations like array_filter or unset preserve the original numeric keys, so code that assumes contiguous zero-based indexing silently breaks. The fix is to remember to call array_values, but that institutional knowledge is the leaky abstraction itself.
The second gripe is the type system bolted onto class properties. Typed properties have an uninitialized state distinct from null, and touching one before assignment throws a fatal error rather than a warning. That collides badly with deserialization workflows where missing fields are routine, and it leaves developers juggling is_null, isset, property_exists, and empty to figure out what state an object is actually in. The author argues nullable properties should just default to null and non-nullables should require initialization, matching how readonly already works.
The broader take is sympathetic: PHP’s reputation is outdated, Laravel and the fast edit-reload loop are genuine strengths, and modern PHP holds its own as a general-purpose language. The rough edges are legacy compromises from grafting a type system onto a dynamic foundation, not reasons to dismiss it.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.