Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82275 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37229 invoked from network); 9 Feb 2015 12:28:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 12:28:08 -0000 X-Host-Fingerprint: 88.149.172.234 88-149-172-234.v4.ngi.it Received: from [88.149.172.234] ([88.149.172.234:17567] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/31-50460-7D7A8D45 for ; Mon, 09 Feb 2015 07:28:07 -0500 Message-ID: To: internals@lists.php.net Date: Mon, 09 Feb 2015 13:27:20 +0100 User-Agent: tt v. 1.0.5; www.icosaedro.it/tt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <9E1C2427-0295-4F3E-BD29-04DA84321067@ajf.me> X-Posted-By: 88.149.172.234 Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: salsi@icosaedro.it (Umberto Salsi) ajf@ajf.me (Andrea Faulds) wrote: > * Always allowing implicit conversions from int to float is sometimes > going to cause data loss, so it may also be reasonable for PHP to > prevent this specific case IMHO, automatic conversion int --> float is perfectly reasonable because: 1) int can always be converted to float, possibly loosing some less significant digists (int on 64-bit PCs can contain up to 19 digits, float contains up to about 16 digits); 2) the called function is already aware (according to the contract of its interface accepting float) that the passed value is an "approximated representation of a number", and should also be aware of all the limitations of the floating-point arithmetic. > * Requiring an exact type match has the least mental overhead, and > allows types to be checked at compile-time Agree with the first part of the sentence (saving neural cells, specially when you have to understand someone else's code...), but there is no need for a "compiler" to garantee the type-safety of a program: static validation can be used right now on PHP using DocBlocks only, without the need to add new features or to change the current syntax of the language. For example: /** * @param float $x * @param float $y * @return float */ function modulus($x, $y) { return sqrt($x*$x + $y*$y); } echo modulus(1,1); can be easily statically validated and is perfectly equivalent to the possible new syntax: function modulus(float $x, float $y): float { return sqrt($x*$x + $y*$y); } echo modulus(1,1); Rather than changing PHP trying to (badly) imitate other languages, the language might evolve in another completely different direction preserving its nature of scripting language, but paying more attention designing its features (syntax, libraries, etc.) so that static validation and eventually compilation into an efficient binary executable code can be performed. Regards, ___ /_|_\ Umberto Salsi \/_\/ www.icosaedro.it