Re: What do we need strict scalar type hints for?

From: Date: Thu, 05 Feb 2015 19:15:27 +0000
Subject: Re: What do we need strict scalar type hints for?
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-81959@lists.php.net to get a copy of this message
On Thu, Feb 5, 2015 at 9:50 PM, Andrea Faulds <ajf@ajf.me> wrote: > Hi, > > > On 5 Feb 2015, at 06:52, Dmitry Stogov <dmitry@zend.com> wrote: > > > > I completely agree. > > Strict typing doesn't fit into PHP. It was already told thousand times. > > Seems to work rather well in practice, so long as it’s optional. > "works" and "fits" are different. > > Also, the only really useful case for "strict typing" is the ability to > catch mistakes in user apps. > > However, this ability is really limited. Implementing "Design by > Contact" approach may be much smarter. > > It’s not that limited. I caught two different bugs in my app simply by > adding strict types. > > Strict typing, crucially, allows the catching of errors ahead of time, > too. You can’t do that with weak typing, because it depends on the value, > not the type. And you don’t know the value from reading the source code. > Strict type hinting may help catching problems only at run-time. In PHP you almost never can do something ahead of time, because of run-time binding. You may only guess, analyzing the whole projects and performing type inference. Thanks. Dmitry. > > -- > Andrea Faulds > http://ajf.me/ > > > > >

« previous php.internals (#81959) next »