Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80645 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16906 invoked from network); 16 Jan 2015 15:37:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2015 15:37:50 -0000 Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:34589] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 65/A2-00273-C4039B45 for ; Fri, 16 Jan 2015 10:37:50 -0500 Received: by mail-ob0-f170.google.com with SMTP id wp4so3933730obc.1 for ; Fri, 16 Jan 2015 07:37:45 -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=8ch7iBZBpyu0H6rjv5t+zO8kyIIgJT0gEM7L7N99mfw=; b=syE76vVyYeazxxgIijgUWrMC0GeYM8D91rlkp5o9KOjDMQcdes+5XgZAMKmWMzqygv P7tAOLy/u0//L00yjFTOx/HWN+NJuIuuV6R+U6aAbT43THa+C//TM5ZwX90AFKWoLTQr a6cgWWf13PeF+c+ZXFsSFWCTbB+pjKJn7PdmI= 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=8ch7iBZBpyu0H6rjv5t+zO8kyIIgJT0gEM7L7N99mfw=; b=Kns+AdGTtZpIO+oKNIj1ZppbiNCDGsLVZ+Opj/W1zeEKki/3tbEC9qgnJvwwwQ36z1 l5GqrKMQ2FhqSQ8YajlqLbf7HyzL8VbngYSqtAUbojVxD9g8SnsG9KIKFlWzBpjLydwF IAYo32IyvZg69TpZvTbf8cVhxjn1x2LqKbe9AsZu/s2XuNIUFRIJ2RUUSeHo2ho4liE8 OboXE5eYjwt79JiXjtm2BelkTFo+oM09rFDH9GMZIADoxUC/UA1S2mzPfCvF0vdlZhKY u3UH9+YL2iA6PKT+Crw/vGDdbCxYY8kx3xb/vEIJ/xLD9uOATPP8wj8WluJGNM5TjRxg cfFQ== X-Gm-Message-State: ALoCoQmPGf/ynRUTpLn+nw/w33W33WdMu3Osn60DmSjyrfU29ZJ9wTijHzw/h7d9l2Dgd2dDJzux MIME-Version: 1.0 X-Received: by 10.202.196.206 with SMTP id u197mr9259876oif.21.1421422665778; Fri, 16 Jan 2015 07:37:45 -0800 (PST) Received: by 10.202.214.146 with HTTP; Fri, 16 Jan 2015 07:37:45 -0800 (PST) In-Reply-To: <54B925B8.1010601@gmail.com> References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> <4E2073DE-0951-498C-97BB-DDAC094F11FA@ajf.me> <9a033dd1f223f854e760924d118ab812@mail.gmail.com> <2ae0164cb9b9bf1c974d7a3c60af0466@mail.gmail.com> <6105ea99002e634373c09685310e26a6@mail.gmail.com> <54B90431.10903@gmail.com> <54B925B8.1010601@gmail.com> Date: Fri, 16 Jan 2015 17:37:45 +0200 Message-ID: To: Rowan Collins Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints v0.2 From: narf@devilix.net (Andrey Andreev) Hi again, On Fri, Jan 16, 2015 at 4:52 PM, Rowan Collins wrote: > > Specifically, I don't think a library author should be able to tell me that, > just because they're feeling picky, '42' and 42 are not equivalent when > calling their function. It does very little to protect me from genuine > mistakes (passing completely the wrong parameter), and makes my life as user > of the library harder. > With no attempt to argue, I just thought of another example, inspired by the ones given in the RFC - it is fairly common for functions dealing with times to only accept a UNIX timestamp or otherwise just a single kind of a time unit, such as only a count of minutes or days. So where '7 years' is passed and and accepted when using a weak hint (by truncating the trailing non-numeric characters), a strict hint on the other hand may prevent the input of incorrect data (given that it's not years that are expected, of course). While typing that, I thought of another possible improvement that may be made regardless of strict, weak or no scalar type hints are implemented. I'm not sure if it's feasible due to the parser/compiler/whatever possibly not having access to this info, so I hope that somebody confirms that ... Can it be made for the error messages to mention the *parameter name* instead of only its number? Take the following example: function fubar(string $data, int $mode) {} fubar('dummy', 'non-integer'); A 'fubar() expects parameter 2 ($mode) to be integer, string given' would be substantially more useful in case of wrong input. Cheers, Andrey.