RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)

From: Date: Mon, 14 Jul 2014 18:04:50 +0000
Subject: RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-75504@lists.php.net to get a copy of this message
> -----Original Message-----
> From: Andrea Faulds [mailto:ajf@ajf.me]
> Sent: Monday, July 14, 2014 8:59 PM
> To: Zeev Suraski
> Cc: Rowan Collins; internals@lists.php.net
> Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
>
>
> On 14 Jul 2014, at 18:52, Zeev Suraski <zeev@zend.com> wrote:
>
> > Type hints were first and foremost introduced for object oriented
> > safety, as a part of the major OO model shift Andi and I pushed for in
> > PHP 5.0.  What you may be alluding to - type hints for arrays and
> > objects - were added at later time and introduced that small
inconsistency
> you're talking about.
> > Still, type juggling for scalars has been the fundamental nature of
> > PHP since the get go;  Type jugging for arrays/objects was always more
> > of an edge case and perhaps even a misfeature.
>
> I'm not sure we actually do "juggle" arrays and objects much, do we? You
can
> cast to them, sure, because PHP as a rule allows you to cast anything to
> anything explicitly (bar resources), but I can't, for example, do a
loose
> comparison between an array and a string.

Exactly, that's my point.  While you can explicitly cast scalars to arrays
and even objects, it's an edge case and arguably a misfeature, and (IIRC)
never happens implicitly.  And of course there's no way to turn a scalar
into a specific type of object or a resource.

Zeev


Thread (250 messages)

« previous php.internals (#75504) next »