Taking PHP Seriously

So the current state of PHP’s semantics is that objects are passed by reference (choosing Java over, say, C++), primitive types are passed by value (where Java, C++, and PHP agree), but the older reference semantics and & notation persist, sometimes interacting with the new world in weird ways.Failure-oblivious philosophy..PHP tries very, very hard to keep the request running, even if it has done something deeply strange..For instance, division by zero does not throw an exception, or return INF, or fatally terminate the request..By default, it warns and evaluates to the value false..Since false is silently treated as 0 in numeric contexts, many applications are deployed and run with undiagnosed divisions by zero..This particular issue is changed in PHP 7, but the design impulse to keep plowing ahead, past when it could possibly make sense, pervades libraries too.Inconsistencies in the standard library..When PHP was young, its audience was most familiar with C, and many APIs used the C standard library’s design language: six-character lower case names, success and failure returned in an integer return value with “real” values returned in a callee-supplied “out” param, etc..As PHP matured, the C style of namespacing by prefixing with _ became more pervasive: mysql_…, json_…, etc..And more recently, the Java style of camelCase methods on CamelCase classes has become the most common way of introducing new functionality..So sometimes we see code snippets that interleave expressions like new DirectoryIterator($path) with if (!($f = fopen($p, ‘w+’)) … in a jarring way.Lest I seem like an unreflective PHP apologist: these are all serious problems that make defects more likely..And they’re unforced errors..There’s no inherent trade-off between the Good Parts of PHP and these problems.. More details

Leave a Reply