RE: [PHP-DEV] [RFC][Accepted] Scalar Type Declarations V0.5
| From: | Thomas Punt | Date: | Wed, 18 Mar 2015 12:21:06 +0000 |
| Subject: | RE: [PHP-DEV] [RFC][Accepted] Scalar Type Declarations V0.5 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85186@lists.php.net to get a copy of this message | ||
Hey Pavel,
> 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; });
Result: catchable fatal error
Reason: invocation context is in strict mode
> // 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; });
Result: no error
Reason: invocation context is in weak mode
> I can't find this in the RFC. I'd intuitively expect error in the
> first example and the second one to work OK.
Correct :)
-Tom