Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81732 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50085 invoked from network); 3 Feb 2015 19:32:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2015 19:32:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=sd@sven-drieling.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sd@sven-drieling.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sven-drieling.de from 178.77.76.68 cause and error) X-PHP-List-Original-Sender: sd@sven-drieling.de X-Host-Fingerprint: 178.77.76.68 energy.rubisco.eu Linux 2.6 Received: from [178.77.76.68] ([178.77.76.68:56127] helo=energy.rubisco.eu) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/46-20608-26221D45 for ; Tue, 03 Feb 2015 14:32:51 -0500 Received: from main (dynadsl-080-228-202-114.ewetel.net [80.228.202.114]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by energy.rubisco.eu (Postfix) with ESMTPSA id 03AD111B7C001; Tue, 3 Feb 2015 20:32:46 +0100 (CET) Date: Tue, 3 Feb 2015 20:07:57 +0100 To: Christoph Becker Cc: Thomas Bley , dmitry@zend.com, ajf@ajf.me, nikita.ppv@gmail.com, internals@lists.php.net Message-ID: <20150203200757.6b29a758@main> In-Reply-To: <54CFFC5D.4000802@gmx.de> References: <20150202210349.6FB91261948@dd15934.kasserver.com> <54CFE965.2080905@gmx.de> <20150202214254.BEB88261948@dd15934.kasserver.com> <54CFFC5D.4000802@gmx.de> Organization: Indy X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] What do we need strict scalar type hints for? From: sd@sven-drieling.de (Sven Drieling) Am Mon, 02 Feb 2015 23:38:21 +0100 schrieb Christoph Becker : Hallo, > >> addVat(-1); > > Well, my point was that even a strict type system doesn't necessarilly > catch all erroneous/undesired arguments. Even if addVat() properly > handles negative numbers, and maybe even zeroes, there are functions > that can't. What about scalar type declaration in userland? namespace mytypes; declare scalartype amount($amount) { if (!is_int($amount) && !is_float($amount)) { throw new InvalidArgumentException('Argument amount must be of the type int|float, '.gettype($amount).' given'); } } function addVat(mytypes\amount $amount) { return round($amount*1.19, 2); } addVat(42) // OK addVat("42") // OK addVat(-42) // OK addVat(42.0) // OK addVat(true) // Exception var mytypes\amount $amount = 0; $amount = 42; // OK $amount = "42"; // OK $amount = true; // Exception tschuess [|8:)