Re: Re: [RFC-Discuss] Scalar Type Declarations v0.5
| From: | Dmitry Stogov | Date: | Wed, 25 Feb 2015 15:37:24 +0000 |
| Subject: | Re: Re: [RFC-Discuss] Scalar Type Declarations v0.5 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83801@lists.php.net to get a copy of this message | ||
On Wed, Feb 25, 2015 at 6:24 PM, Anthony Ferrara <ircmaxell@gmail.com>
wrote:
> Dmitry
>
> On Wed, Feb 25, 2015 at 10:20 AM, Dmitry Stogov <dmitry@zend.com> wrote:
> >
> >
> > On Wed, Feb 25, 2015 at 6:06 PM, Anthony Ferrara <ircmaxell@gmail.com>
> > wrote:
> >>
> >> Dmitry:
> >>
> >> On Wed, Feb 25, 2015 at 7:55 AM, Dmitry Stogov <dmitry@zend.com> wrote:
> >> > On Wed, Feb 25, 2015 at 2:42 PM, Niktia Nefedov <inefedor@gmail.com>
> >> > wrote:
> >> >
> >> >> On Wed, 25 Feb 2015 16:30:32 +0400, Dmitry Stogov <dmitry@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.
> >> >>
> >> >
> >> > I think it'll work without errors and produce some explainable but
> weird
> >> > output. I didn't run it myself yet.
> >>
> >> "Weird"?
> >>
> >> int(5)
> >> string(1) "5"
> >>
> >> How is that weird? That's precisely what you asked it to do.
> >
> >
> > I just think that not allbody understand this and expect something
> > different.
>
> Looking at that code, even not knowing this RFC and the details of the
> implementation, what would you expect to be different about it?
>
I expected the same, especially because I read the code.
> Now, having read the RFC and played with the patch (even though you
> admitted that you didn't), what would you expect to be different?
>
You already saw, at least one who was in time to make mistake.
I was expecting this :)
Thanks. Dmitry.
>
> Anthony
>