On Wed, 25 Feb 2015 15:42:11 +0400, Niktia Nefedov <inefe...@gmail.com> wrote:

On Wed, 25 Feb 2015 16:30:32 +0400, Dmitry Stogov <dmi...@zend.com> wrote:

anyone may tell, what this will print without running :)

main.php
========
<?php
declare(strict_types=1)
include "a.php";
include "b.php";
var_dump(foo("5"));
?>

a.php
=====
<?php
declare(strict_types=0)
function foo(string $a): string {
    bar($a);
    return $a;
}
?>

b.php
=====
<?php
declare(strict_types=1)
function bar(int &$a) {
    var_dump($a);
}
?>

Thank. Dmitry.


Hi Dmitry,

This will error out because $a in the scope of `foo` will be coerced to int type when passed to bar by reference.

References are a problem for weak-only types as well (even more so I would say, because in a lot of cases they would continue working truncated or changed).

Happily there are not lots of post-php5 code that uses references here and there, but that would be good to add the point about them to both RFCs (and in documentation in future) just so that users would be aware of that.

Ah sorry I was too quick on judging, Florian is right, when foo returns its value it will be coerced back to string because of strict=0 in this case...

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

Reply via email to