The Quirks And Gotchas of PHP
SMRTR summary
Quirks and gotchas lurk in the depths of PHP, ready to surprise unwary developers. Like its cousin JavaScript, PHP's loose typing can lead to unexpected results. "1" + 1 equals 2, not "11" as in JavaScript. But beware: PHP considers the string "0" as false, while any non-empty string is true.
PHP 8 tightens the reins on some of these quirks. The new match expression uses strict comparisons, unlike the looser switch statement. Union types allow for more precise function declarations, helping catch type-related bugs early.
Variable variables and passing by reference add to PHP's unique flavor. $varName = 'hello'; $$varName = 'world'; creates a variable named $hello with the value 'world'.
Arrays in PHP are versatile beasts, serving as both arrays and dictionaries. But watch out: accessing a non-existent element returns null instead of throwing an error.
As PHP evolves, it's shedding some of its more puzzling behaviors, but developers must stay vigilant to avoid these lingering gotchas.
SMRTR provides this summary for quick context. The original article belongs to Daily.dev.
Read the original article