Re: "strict_types" should be renamed "raise_type_error". WAS: About declare(strict_types = 1)
| From: | Yasuo Ohgaki | Date: | Mon, 16 Mar 2015 20:57:45 +0000 |
| Subject: | Re: "strict_types" should be renamed "raise_type_error". WAS: About declare(strict_types = 1) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85090@lists.php.net to get a copy of this message | ||
Hi Matthew and all,
On Tue, Mar 17, 2015 at 5:34 AM, Matthew Leverton <leverton@gmail.com>
wrote:
> On Mon, Mar 16, 2015 at 2:53 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> > 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.
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