Re: Re: [RFC-Discuss] Scalar Type Declarations v0.5
| From: | Dmitry Stogov | Date: | Wed, 25 Feb 2015 12:58:41 +0000 |
| Subject: | Re: Re: [RFC-Discuss] Scalar Type Declarations v0.5 | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83781@lists.php.net to get a copy of this message | ||
On Wed, Feb 25, 2015 at 3:54 PM, Shashank Kumar <shashankkumar.me@gmail.com>
wrote:
> On Wed, Feb 25, 2015 at 4:30 AM, 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.
>>
>>
> As I understand the proposal and above example, it's possible to change
> the 'strict_type' settings per file.
> So, for an enterprise application being developed over many years, it's a
> very realistic scenario
> that this setting will be different in different files especially if
> coding conventions are not followed (happens very often).
>
> Does that mean when reading or writing code, in addition to checking the
> signature of a function,
> I have to check the 'strict_types' setting at the top as well, to
> understand how that signature behaves?
>
I think you should check it in the top line of the file where the function
was called from.
Thanks. Dmitry.
>
> Thanks
> Shashank
>