Re: Is it a good idea to have a "strict" mode?
| From: | Martin Keckeis | Date: | Fri, 30 Jan 2015 10:16:41 +0000 |
| Subject: | Re: Is it a good idea to have a "strict" mode? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81415@lists.php.net to get a copy of this message | ||
>
> You might get more approval for: declare(strict=1);
>
> I would like to see this to help catch typeos in variable names. If a
> variable
> is assigned and it does not already exist some sort of error would be
> raised.
> The inspiration of this is from Perl where 'use strict' does this.
>
> How to declare a variable ? The keyword 'var' exists, it is only used in
> classes
> but could be used to declare variables in functions and at the top level.
>
> Thus:
>
> declare(strict=1);
>
> var $foo; // Declared but not given a value - so give it NULL
> var $bar = 1;
>
> $foo = 234;
>
> $baz = 10; // This would error - $baz is a typeo for $bar
>
>
You can achieve that already quiet simple
<?php
error_reporting(E_ALL);
set_error_handler(function($errno, $errstr, $errfile, $errline){
throw new \Exception($errstr);
});
$a = $b;