Re: A different user perspective on scalar type declarations

From: Date: Thu, 26 Feb 2015 19:14:10 +0000
Subject: Re: A different user perspective on scalar type declarations
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-83915@lists.php.net to get a copy of this message
On 02/26/2015 10:49 AM, Dan Ackroyd wrote: > In most applications, the part of the code that is exposed to the > outside world and has to convert strings or unknown types into known > types is a very small layer at the outside edge of the application. > > The vast majority of code written for non-trivial applications has no > contact with the outside world. Instead it only communicates to other > layers inside the application where the types required are fully > known, and so the parameters passed should already be in the correct > type. And so type coercion is at best unneeded, and usually not > wanted. Looking through some very large code bases I am involved with this argument falls down on two main points: 1. There is a lot of data coming from memcache/mysql/pgsql as strings that is not typed. 2. There are quite a few objects being shuffled around interchangeably with strings and making use __toString magic. Type coercion is needed in both cases here. This is in the backend code far for user input. It would take a whole lot of refactoring to be able to turn on strict for this code. Especially getting rid of all use of __toString objects. It would require force-casts to make this backend code work in strict mode and then we are back to square one. -Rasmus

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#83915) next »