This is a mini-rant, a short essay refuting a common misconception among users of an Internet forum. If you think this essay is FUD, feel free to explain why on the essay's talk page.
Some problems with the PHP programming language are solvable by applying a few coding standards. But others remain painful. I've read the articles "PHP: a fractal of bad design" by Eevee and the "Hardly" rebuttal by ManiacDan. (There are also rebuttals by Jakub Vrána[1] and Dino Beslagic[2]) A lot of these articles about the merits of PHP make inconsistent points. So I'll keep this short so that any inconsistencies can be found and corrected.
JavaScript has plenty of warts, such as the behavior of ==
vs. ===
.
Douglas Crockford's JavaScript: The Good Parts lays out some coding standards that reduce the mental load of programmers producing new code.
Just as in JavaScript, there's a smaller elegant language within PHP struggling to get out, especially since PHP version 5.4.
Similar standards could be laid out for PHP.
ErrorException
class. This snippet converts errors that aren't silenced (operator @
) to exceptions. It also changes the behavior of the silence operator to act not unlike an inline try
for functions that use the "error" system.==
exists===
. In those cases where you want loose comparison, explicitly cast both sides of each expression to the type as which you want to compare them. This way you have to memorize only the casting rules, not the (different) rules for comparison as well, and don't end up inadvertently treating different hash values as equal.[3]php.ini
options are not for deployment to productionscream.enabled
.real
mess. For example, if $db
is a database connection object, you can use $db->quote
(for PDO) or $db->escape_string
(for MySQLi) with statements that cannot be prepared and bound the normal way because they are variadic (especially statements using operator IN
).bindParam()
command, which makes variadic statements possible.fopen()
on URLs with an Internet schemeIn this Slashdot post I mentioned six actual problems with PHP 5, and I later added another.
'10' <= '1e1'
and '10' >= '1e1'
. One can use strcmp
in one's own code and pass sort_flags
to sorting functions that support them, but some functions still use the built-in operators <
and >
that don't even impose a total order. Likewise, switch
uses the built-in ==
comparison operator whose semantics are byzantine.? ... :
operator is the less useful side.from __future__
statements.Changes in PHP 7 diminish these somewhat:
$a ?? $b
acts like $a !== NULL ? $a : $b
, except its associativity is on the correct side so that it can be chained properly: $a ?? $b ?? $c
behaves like SQL COALESCE(a, b, c)
.ImportError
and NameError
exceptions that the caller can catch.But just as importantly, PHP 7 also guarantees that the significant language improvements in 5.4, 5.5, and 5.6 are present, as opposed to the outdated PHP 5.3 included with RHEL 6.x and CentOS 6.x.
[1, 2, 3, 4]
, foo()[0]
, foreach ($array_of_arrays as list(...)) { ... }
yield
finally
function variadic($first_arg, ...$other_args)
and bind($type_strings, ...$argument)
<?=
3 ** 2 == 9 && 2 ** 3 == 8
md5('240610708') == md5('QNKCDZO')
because they both begin with 0e
, which in floating-point notation means "0 times 10 to some power".
open_basedir
enabled because of a heavy-handed security fix.
Categories: Computer science, Mini-rants