On Sun, Feb 8, 2015 at 9:38 AM, Rasmus Lerdorf <ras...@lerdorf.com> wrote:
> On 02/07/2015 05:03 PM, Pavel Kouřil wrote:
>> I'm wishing more and more that the RFC doesn't pass (even though I'd
>> LOVE to have typehints in PHP as a userland developer) and someone
>> else will make a better version of typehints RFC for  PHP 7, because
>> this one feels really like you took an ok-ish RFC (one that would be
>> good for PHP) and slapped a strict typing on it without enough
>> research about strong typing in other languages. And as I said myself
>> multiple times in the past, the declare syntax IS just ugly (and
>> changing how code works by writing one line is an ugly principle as
>> well, IMHO). :(
>
> I am not sure I would go that far. Andrea did plenty of research and has
> tons of experience in other languages, I just think this approach is
> misguided. I also wonder just how many people of those who voted even
> bothered to download and try the patch. I tried it a while back on some
> existing code and it was a nightmare. Does everyone realize that these
> simple things break?
>
>  tan(1);
>  echo strstr("test", "est", 1);
>
> Having absolutely no coercion for int to float and 0/1 to false/true,
> especially for internal functions, is just too pedantic to me. I also
> find this a bit hypocritical:
>
> declare(strict_types=true);
>
> outputs:
>
> Fatal error: strict_types declaration must have 0 or 1 as its value
>
> That is obviously nit-picking, but if we are going to get this pedantic...
>
> And, you also have to realize that it isn't actually per file. For
> example, this:
>
> <?php
> function myErrorHandler($errno, $errstr, $errfile, $errline) {
>   if ($errno===E_RECOVERABLE_ERROR) {
>     echo "\ncatchable fatal error\n";
>     return true;
>   }
>   return false;
> }
> set_error_handler('myErrorHandler');
>
> echo tan(1);
> declare(strict_types=1);
> echo tan(1);
> declare(strict_types=0);
> echo tan(1);
>
> This will output:
>
> 1.5574077246549
> catchable fatal error
> 1.5574077246549
>
> The RFC refers to it as a per-file directive, which just means it
> doesn't apply to files you include after setting it. It doesn't mean
> that the entire file is affected. You can flip in and out of strict mode
> at will. Which isn't necessarily a bad thing, but it can certainly get
> confusing.
>
> For example. Since everyone has already voted, you can all tell me what
> this does, right?
>
> 1)
> <?php
> function do_something() {
>   declare(strict_types=1);
> }
> echo tan(1);
> do_something();
> echo tan(1);
>
> How about this:
>
> 2)
> <?php
> echo tan(1);
> do_something();
> echo tan(1);
> function do_something() {
>   declare(strict_types=1);
> }
>
> or this?
>
> 3)
> <?php
> function do_something() {
>   declare(strict_types=1);
> }
> echo tan(1);
> echo tan(1);
>
> Answers:
>
> 1) fatal error on the first tan(1)
> 2) no errors
> 3) same as 1)
>
> Basically declare() does not respect function scope, but it doesn't let
> you know that. There is a reason we haven't used declare() for anything
> real.

I do not see that as a blocker.

Anyway, if everyone has voted then you do not have to worry as the RFC
is rejected as of now. Badly but so it goes.



-- 
Pierre

@pierrejoye | http://www.libgd.org

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to