Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81655 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53787 invoked from network); 2 Feb 2015 21:18:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 21:18:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.218.44 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.44 mail-oi0-f44.google.com Received: from [209.85.218.44] ([209.85.218.44:54350] helo=mail-oi0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/F5-25089-799EFC45 for ; Mon, 02 Feb 2015 16:18:15 -0500 Received: by mail-oi0-f44.google.com with SMTP id a3so46049074oib.3 for ; Mon, 02 Feb 2015 13:18:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=SC0sVBP7mBCoeifNQWaATYeeRpwS51JTkjKAVLaQOjI=; b=GqAHBPYrQOU7+QMzNkqTZnmC1/8FA6xoC3PobkdlX9UhGEWJd9CugBW9fPcolnBnlb EjZE2tlr1z2CV2TCw0CAUnXLj+5I6y4YEZvh+jbdyfSLxglIgEqMy0ziPhum3wdtXTx8 gDWexfl0FEKMgKysDBprWT5hGnJm7d1GwvdhE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=SC0sVBP7mBCoeifNQWaATYeeRpwS51JTkjKAVLaQOjI=; b=gf5686JEQb6qXi2/js7kTMIpqqGgG//B1T8o4Zq2aQB5bCaPzbDJzbhCaI+Qn0CbBX p4WxJw6MqTefnzhYFSXJj8AR6Kgl8E37ELgH1LN2nK5Ay29GScWpWpmqJbZ6K02jnDj4 qLVu/sdbChclRZMMUJFmIg4BkfAGxtCyoxPz9N894HsJMlolgNjS8B909ZgarZrb2mHj 2UJWd4wvMKDWv05qnb/XYmCpfeyZRE3PeUd0MmblQhKt82pIxWRjW/+z70nHoxUQS3PG iizcKIrx7Dd0tnqkWQD0DydehrbO3l1jCa6s+Ob+WYj/F5GP2gP2FLr+7ODuA21Rs88R AAhA== X-Gm-Message-State: ALoCoQk8O9BH0qqe1Pta6tKMQn6UHJmtFgoXzSDixS84fYoMlMTuQbUR0WH5t+btfmFO+N5h59Wm MIME-Version: 1.0 X-Received: by 10.60.70.141 with SMTP id m13mr13336986oeu.86.1422911892265; Mon, 02 Feb 2015 13:18:12 -0800 (PST) Received: by 10.202.214.205 with HTTP; Mon, 2 Feb 2015 13:18:12 -0800 (PST) In-Reply-To: <20150202210349.6FB91261948@dd15934.kasserver.com> References: <20150202210349.6FB91261948@dd15934.kasserver.com> Date: Mon, 2 Feb 2015 23:18:12 +0200 Message-ID: To: Thomas Bley Cc: Dmitry Stogov , Andrea Faulds , Nikita Popov , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] What do we need strict scalar type hints for? From: narf@devilix.net (Andrey Andreev) Hi, On Mon, Feb 2, 2015 at 11:03 PM, Thomas Bley wrote: > Here is a typical billing example which uses exceptions: > > ini_set('error_reporting', E_ALL); > ini_set('display_errors', 1); > > addVat('apples'); > > function addVat($amount) { > if (!is_int($amount) && !is_float($amount)) { > throw new InvalidArgumentException('Argument 1 passed to '.__FUNCTION__.' must be of the type int|float, '.gettype($amount).' given'); > } > return round($amount*1.19, 2); > } > > Instead of multiple strict scalar hints (e.g. function addVat(int|float $amount){...}), I would prefer to have "numeric" as strict type: > function addVat(numeric $amount){...} > That is an example where a weak hint to float would be better. Here's a more appropriate example that I gave in the other thread: http://marc.info/?l=php-internals&m=142142272705938&w=2 Cheers, Andrey.