Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58394 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90941 invoked from network); 1 Mar 2012 08:54:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2012 08:54:45 -0000 Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=permerror Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass 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 Linux 2.6 Received: from [78.32.209.33] ([78.32.209.33:63261] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/0D-46815-1593F4F4 for ; Thu, 01 Mar 2012 03:54:45 -0500 Received: from addw by mint.phcomp.co.uk with local (Exim 4.63) (envelope-from ) id 1S31mY-000105-MV for internals@lists.php.net; Thu, 01 Mar 2012 08:54:38 +0000 Date: Thu, 1 Mar 2012 08:54:38 +0000 To: internals@lists.php.net Message-ID: <20120301085438.GA3485@phcomp.co.uk> Mail-Followup-To: internals@lists.php.net References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.2i Organization: Parliament Hill Computers Ltd Subject: Re: [PHP-DEV] Scalar Type Intentions From: addw@phcomp.co.uk (Alain Williams) On Wed, Feb 29, 2012 at 09:01:05PM -0500, Adam Jon Richardson wrote: > However, the lack of scalar hinting does limit the ability of a developer > to declare his/her intentions for function/method parameters. A non-hinted > parameter expecting a scalar could be sent an object or an array, breaking > the expectations (and much of the time, the functionality) of the code. > That is to say, there is a value in declaring what the parameter IS NOT, > too. +1 > *What if PHP added the hint scalar?* The example could be rewritten as: > > function foo(scalar $arg){ > // $arg is supposed to be a scalar and will be used as an int > } > > The idea is that the failure to send a valid scalar argument to the > function would result in the same feedback that currently occurs when array > or object hints are not heeded. Now, the expectations for each > function/method parameter can be explicitly declared (or, at least, more > explicitly.) > And, *what if PHP added the following aliases for the hint scalar*: > > - bool > - int > - float > - string > > The function could then be rewritten as below: > > function foo(int $arg){ > // $arg is supposed to be a scalar and will be used as an int > } A nice compromise for a heated issue. This would also open the way to more complete checking (as has been discussed) at some time in the future. It would provide a better alternative to some of the ghastly pseudo comment conventions that are currently used as means of documentations. Programming is about communication of intent, not just with the computer (compiler) but also with programmers who subsequently read the code. -- 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