Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81418 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19464 invoked from network); 30 Jan 2015 10:27:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2015 10:27:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=permerror Received-SPF: pass (pb1.pair.com: domain phcomp.co.uk designates 78.32.209.33 as permitted sender) X-PHP-List-Original-Sender: addw@phcomp.co.uk X-Host-Fingerprint: 78.32.209.33 freshmint.phcomp.co.uk Received: from [78.32.209.33] ([78.32.209.33:56765] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8C/A4-31101-B7C5BC45 for ; Fri, 30 Jan 2015 05:27:07 -0500 Received: from addw by mint.phcomp.co.uk with local (Exim 4.72) (envelope-from ) id 1YH8n1-0000tr-DZ for internals@lists.php.net; Fri, 30 Jan 2015 10:27:03 +0000 Date: Fri, 30 Jan 2015 10:27:03 +0000 To: internals@lists.php.net Message-ID: <20150130102703.GD4250@phcomp.co.uk> Mail-Followup-To: internals@lists.php.net References: <54CB13A4.9060900@rodas.me> <20150130093558.GC4250@phcomp.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Parliament Hill Computers Ltd User-Agent: Mutt/1.5.20 (2009-12-10) Subject: Re: [PHP-DEV] Is it a good idea to have a "strict" mode? From: addw@phcomp.co.uk (Alain Williams) On Fri, Jan 30, 2015 at 11:16:41AM +0100, Martin Keckeis wrote: > > > > 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 > error_reporting(E_ALL); > > set_error_handler(function($errno, $errstr, $errfile, $errline){ > throw new \Exception($errstr); > }); > > $a = $b; That catches the use of an undefined variable $b. What I am talking about is assignment to an *undeclared* variable $baz (or $a). This is not caught by your code - PHP does not have a concept of declaring variables. -- 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