Re: Re: [RFC] Scalar Type Hints v0.2

From: Date: Thu, 05 Feb 2015 01:15:55 +0000
Subject: Re: Re: [RFC] Scalar Type Hints v0.2
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi Pascal,

> On 5 Feb 2015, at 00:02, Pascal Chevrel <[email protected]> wrote:
> 
> I am probably going to ask a stupid question, but do we really need the =1 part in declare?
> 
> declare(strict_types=1) couldn't be declare(strict_types)?
> 
> Or does it mean that there would be cases when strict typing would be deactivated after being
> activated with declare(strict_types=0)?

Oh, I made it like that because that’s the existing syntax of declare(), it takes a name and a
value. But I suppose it could be modified to allow just a name. I don’t think we should modify it
just for this specific case, really… less exceptions to a rule and more consistency are generally
a good thing.

There is a use for declare(strict_types=0), which is to make part of a file weak while having the
rest strict. It’s not something you’d want to do very often, but it may be useful in some rare
cases. If we have declare(strict_types=1), then it makes sense to also have declare(strict_types=0).
It’d be rather odd to not allow it.

> To be honest, I don't like declare() because it looks like a function call, not a setting
> for the file like a namespace declaration would be. Also, in the case of declare(ticks=1), 1 is not
> a boolean but an interval so I find it a bit confusing that strict_types=1 would be a boolean in
> that case. Or maybe declare(strict_types=true) then?

I originally had it be a boolean, but considering how often this would be used, I changed it to 1
for terseness. Using 1 is common for INI settings, so I don’t think it’d be that confusing, but
I see your point.

> Personnally I would prefer a syntax like:
> declare strict;
> 
> which is just shorter and more readable in my opinion. I know it is mostly cosmetic but I
> don't really understand why declare uses parenthesis if it is a language construct and not a
> function (and yes, I think that declare(ticks=1) also looks silly ;) );
> 
> So basically instead of that at the top of my files:
> <?php
> namespace Foo;
> use Bar;
> declare(strict_types=1);
> 
> I would prefer having that:
> <?php
> namespace Foo;
> use Bar;
> declare strict;
> 
> It's probably a detail in the whole discussion, but for some weird psychological reason,
> it matters to me :),

I can see the appeal, though I’m not really sure about adding new syntax just for this.

By the way, I think declare() would be easily distinguished from a function for two reasons.
Firstly, you can’t assign to constants, and secondly, it’ll be syntax-highlights differently.

I can understand your concerns, though. :)

Thanks for voicing them.
--
Andrea Faulds
http://ajf.me/






Thread (148 messages)

« previous php.internals (#81854) next »