Re: [RFC][Accepted] Scalar Type Declarations V0.5
| From: | Yasuo Ohgaki | Date: | Wed, 18 Mar 2015 04:25:38 +0000 |
| Subject: | Re: [RFC][Accepted] Scalar Type Declarations V0.5 | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85163@lists.php.net to get a copy of this message | ||
Hi Andre,
On Wed, Mar 18, 2015 at 8:53 AM, André Rømcke <andre.romcke@ez.no> wrote:
> TL;DR; weak mode is for api consumers, aka normal php users, while strict
> is
> for the actual target users of this features: api (library/framework)
> creators.
>
How could it possible?
On Mon, Mar 16, 2015 at 2:49 PM, Dennis Birkholz <dennis@birkholz.biz>
wrote:
> Am 16.03.2015 um 06:28 schrieb Xinchen Hui:
> > lib.php
> > <?php
> > declare(strict_types = 1);
> > function add(int $a, int $b) {
> > }
> >
> > <?php
> > add($_GET['a'], $_GET['b']);
> >
> > that means, I need to add a lots of (int) while I try to call a
> > function in a library which is not written by myself.
>
> that is not right and has been discussed a thousand times over.
> The declare changes the rules only for function calls in the file it is
> declared in.
>
> so:
> lib.php:
> <?php
> declare(strict_types = 1);
> function foo(int $a) {
> // no function call here
> }
> ?>
> The declare here does just nothing.
>
> <?php
> require "lib.php";
> foo("123"); // will work
> ?>
>
> <?php
> declare(strict_types = 1);
> require "lib.php";
> foo("123"); // will give an error
> ?>
>
> Very easy, explained a thousand times over. Bringing up the same false
> arguments up again and again does really not help the discussion.
>
I didn't have my time to spent for the patch. So I don't verify this
by myself, but it seems common sense for this RFC.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net