On Wed, Mar 18, 2015 at 1:13 PM, Nikita Nefedov <inefe...@gmail.com> wrote:
>
> On 18 Mar 2015 14:32, "Pavel Kouřil" <pajou...@gmail.com> wrote:
>>
>> On Wednesday, March 18, 2015, Patrick ALLAERT <patrickalla...@php.net>
>> wrote:
>> > Le mer. 18 mars 2015 à 10:56, Pavel Kouřil <pajou...@gmail.com> a écrit
>> > :
>> >>
>> >> Hello,
>> >>
>> >> how will these examples work btw?
>> >>
>> >> // a.php
>> >> <?php
>> >> declare(strict_types=1);
>> >> function foo($fn) {
>> >>     $fn("1");
>> >> };
>> >>
>> >> // b.php
>> >> <?php
>> >> require 'a.php';
>> >> foo(function (int $a) { return $a * 2; });
>> >>
>> >>
>> >>
>> >> // c.php
>> >> <?php
>> >> function foo($fn) {
>> >>     $fn("1");
>> >> };
>> >>
>> >> // d.php
>> >> <?php
>> >> declare(strict_types=1);
>> >> require 'c.php';
>> >> foo(function (int $a) { return $a * 2; });
>> >>
>> >> I can't find this in the RFC. I'd intuitively expect error in the
>> >> first example and the second one to work OK.
>> >
>> > Your intuition is correct.
>> >
>> >>
>> >> But at the same time, if there will be an error in the first example,
>> >> it is IMHO a huge flaw with this RFC. :/
>> >
>> > Flaw vs. design choice. This is one of the reason that this aspect,
>> amongst others, has been very debated.
>>
>> But if it works this way, the strict mode isn't optional and users of a
>> library NEED to care which mode the library uses?
>
> If library chose to use strict mode then the odds are it will take care of
> passing right types to callbacks and interfaced methods.
>
> Saying that strict mode isn't optional is not true, I don't see why you have
> made this conclusion.

Hello,

I made that conclusion because in the first example, the library kinda
forces strict mode rules on the caller, even if he doesn't want to use
strict mode - this makes the interoperability of the two modes
problematic.

Also, the other possible outcome of the scenario (respecting the mode
of the place where the callback is declared), is IMHO problematic as
well, because it does not respect the strict mode of the place where
it is called, making it inconsistent with how the dual mode RFC works
in general.

Regards
Pavel Kouril

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

Reply via email to