RE: [PHP-DEV] Scalar Type Declaration Syntax Weirdness

From: Date: Tue, 24 Nov 2015 15:42:09 +0000
Subject: RE: [PHP-DEV] Scalar Type Declaration Syntax Weirdness
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-89377@lists.php.net to get a copy of this message
> On Tue, Nov 24, 2015 at 8:10 AM, Sebastian Bergmann <sebastian@php.net> > wrote: > >> The following is currently valid PHP 7 code >> >> <?php >> function a(\int $i) {} >> >> Is it intentional that the \ in front of the "int" is allowed? IMHO, this >> confusing notation must not be allowed. >> >> >> Why not? Its a root level type, you can prefix a \ on any other root level > type that's valid for use in type hinting. > > function a(\DateTime $d) {} > function b(\SplFileObject $f) {} > > Also, this is the only way to get some IDEs to recognize the type when in a > namespace (at least currently). The difference is that DateTime and \DateTime mean different things inside a namespace. int and \int always mean the same thing, so it seems confusing to allow the latter syntax as if it means something different.

« previous php.internals (#89377) next »