On Fri, Jan 30, 2015 at 02:16:20AM -0300, César Rodas wrote: > Hi! > > I'm wondering if it would be a good idea to have a `strict` mode in PHP. > Many language have them and it is a good idea. > > I think it should be a bit different in PHP, it should encourage the > following things: > > - Avoid deprecated things, it should throw an exception. > - Avoid explicit conversions of undefined constants to strings. > - Anything else that could make run-time slower *or* bad practice. > > ```php > "use strict"; > > var_dump(FOOBAR); // should throw an exception, undefined constant. > ``` > > Good idea?
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 -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h> -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php