# "strict_types" should be renamed "raise_type_error". WAS: About declare(strict_types = 1)

- Thread: https://externals.io/message/85083
- Original archive: https://news-web.php.net/php.internals/85083
- Started by Yasuo Ohgaki on 2015-03-16T19:53:34+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #85083 — Yasuo Ohgaki — 2015-03-16T19:53:34+00:00

URL: https://externals.io/message/85083#85083

Hi all,

I think this is important, but not many people realize the importance.
Therefore I created this as a new thread at the last minutes of vote.

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:
> > […]
>
> 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
> ?>
>
>
If this kind of behavior is allowed, why "strict mode" is called strict?
It's not
strict at all if mode could be overridden.

"strict_mode" is just controlling errors, then it should be named as error
controlling directive and raise E_WARNING/E_TYPE or whatever.

Even if what its controlling is error that can be overridden by caller, yet
calling it "strict_types" is not correct. Proper name would be something
like "raise_type_error".

Let's see how it looks if "strict_types" is renamed to "raise_type_error"

<?php
        declare(raise_type_error = 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(raise_type_error = 1);
        require "lib.php";
        foo("123"); // will give an error
?>

Is everyone feel OK with this??

There are other things I would like to mention, but this would be enough
to change decision hopefully.

Regards,

P.S. If we are going to introduce strict types for basic types, what we
really need is type affinity for inputs. e.g. $_GET/$_POST/$_COOKIE.
https://www.sqlite.org/datatype3.html

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #85087 — pajousek@gmail.com — 2015-03-16T20:21:27+00:00

URL: https://externals.io/message/85083#85087 · In reply to: #85083

> Hi all,
>
> I think this is important, but not many people realize the importance.
> Therefore I created this as a new thread at the last minutes of vote.
>
> On Mon, Mar 16, 2015 at 2:49 PM, Dennis Birkholz <dennis@birkholz.biz>
>  wrote:
>
> > […]
> If this kind of behavior is allowed, why "strict mode" is called strict?
> It's not
> strict at all if mode could be overridden.
>
> "strict_mode" is just controlling errors, then it should be named as error
> controlling directive and raise E_WARNING/E_TYPE or whatever.
>
> Even if what its controlling is error that can be overridden by caller, yet
> calling it "strict_types" is not correct. Proper name would be something
> like "raise_type_error".
>
> Let's see how it looks if "strict_types" is renamed to "raise_type_error"
>
> <?php
>         declare(raise_type_error = 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(raise_type_error = 1);
>         require "lib.php";
>         foo("123"); // will give an error
> ?>
>
> Is everyone feel OK with this??
>
> There are other things I would like to mention, but this would be enough
> to change decision hopefully.
>
> Regards,
>
> P.S. If we are going to introduce strict types for basic types, what we
> really need is type affinity for inputs. e.g. $_GET/$_POST/$_COOKIE.
> https://www.sqlite.org/datatype3.html
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net

Hello,

this would make more sense than "strict types", which is a bad name
anyways (as I already mentioned in some other email) - because the
concept of non-week typing is usually called "strongly typed" in any
other language I can think of. Does PHP have to be a special
snowflake?

Regards
Pavel Kouril

---

## #85088 — Matthew Leverton — 2015-03-16T20:34:21+00:00

URL: https://externals.io/message/85083#85088 · In reply to: #85083

> Hi all,
>
> I think this is important, but not many people realize the importance.
> Therefore I created this as a new thread at the last minutes of vote.
>
...
>
> "strict_mode" is just controlling errors, then it should be named as error
> controlling directive and raise E_WARNING/E_TYPE or whatever.
>
> Even if what its controlling is error that can be overridden by caller, yet
> calling it "strict_types" is not correct. Proper name would be something
> like "raise_type_error".
>
> Let's see how it looks if "strict_types" is renamed to "raise_type_error"
>
...
> <?php
>         declare(raise_type_error = 1);
>         require "lib.php";
>         foo("123"); // will give an error
> ?>
>
I agree that the name doesn't by itself explain the feature, but how
could it possibly? You'd end up with something like:

declare(raise_type_errors_on_parameter_mismatches_when_calling_functions_from_this_file_regardless_of_where_the_functions_are_defined_and_what_the_setting_is_in_other_files=1);

I don't think your suggestion explains the feature any better than
strict_types. (Although the irony of using =1 instead of =true isn't
lost on me!)

--
Matthew Leverton

---

## #85090 — Yasuo Ohgaki — 2015-03-16T20:57:45+00:00

URL: https://externals.io/message/85083#85090 · In reply to: #85088

Hi Matthew and all,

On Tue, Mar 17, 2015 at 5:34 AM, Matthew Leverton <leverton@gmail.com>
wrote:

> 
> > […]
> ...
> > […]
> error
> > […]
> yet
> > […]
> ...
> > […]
> I agree that the name doesn't by itself explain the feature, but how
> could it possibly? You'd end up with something like:
>
>
> declare(raise_type_errors_on_parameter_mismatches_when_calling_functions_from_this_file_regardless_of_where_the_functions_are_defined_and_what_the_setting_is_in_other_files=1);
>
> I don't think your suggestion explains the feature any better than
> strict_types.


The word "strict" is not right word for the feature. It should not be used
to avoid
confusions at least.

Anyway, my point is "Is everyone feel right about following behavior"
regardless of
directive name.

<?php
        declare(raise_type_error = 1); // declare(strict_types=1) with the
RFC
        function foo(int $a) {
        // no function call here
        }
?>
The declare here does just nothing.

<?php
        require "lib.php";
        foo("123"); // will work
?>

<?php
        declare(raise_type_error = 1); // declare(strict_types=1) with the
RFC
        require "lib.php";
        foo("123"); // will give an error
?>

This is the same basically as

<?php
        error_reporting(E_TYPE);
        function foo(int $a) {
        // no function call here
        }
?>
The `error_reporting()` here does just nothing.

<?php
        require "lib.php";
        foo("123"); // will work
?>

<?php
        $old = error_reporting(E_TYPE);
        require "lib.php";
        error_reporting($old);
        foo("123"); // will give an error
?>

Does this make sense?

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #85183 — Patrick ALLAERT — 2015-03-18T11:42:44+00:00

URL: https://externals.io/message/85083#85183 · In reply to: #85088

Le lun. 16 mars 2015 à 21:34, Matthew Leverton <leverton@gmail.com> a
écrit :

> (Although the irony of using =1 instead of =true isn't lost on me!)
>

Yes, I mentioned[1] that funny aspect earlier.

0 or 1 is explicitly required in order to update the boolean behind it
while true/false generates a fatal error with "strict_types declaration
must have 0 or 1 as its value".

[1] https://twitter.com/patrick_allaert/status/568167144363560961

---

## #85184 — Pierre Joye — 2015-03-18T11:57:17+00:00

URL: https://externals.io/message/85083#85184

>
> Le lun. 16 mars 2015 à 21:34, Matthew Leverton <leverton@gmail.com> a
> écrit :
>
> > […]
>
> Yes, I mentioned[1] that funny aspect earlier.
>
> 0 or 1 is explicitly required in order to update the boolean behind it
> while true/false generates a fatal error with "strict_types declaration
> must have 0 or 1 as its value".
>
> [1] https://twitter.com/patrick_allaert/status/568167144363560961

Ok.

You do not like this RFC, we get it.

Now, what's about actually being constructive and if you find bug (and
please under the context of this RFC and how it works) please report a bug
so it can be fixed.
