Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80122 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94194 invoked from network); 3 Jan 2015 19:46:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jan 2015 19:46:50 -0000 Authentication-Results: pb1.pair.com header.from=sbj.ml.read@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=sbj.ml.read@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.173 as permitted sender) X-PHP-List-Original-Sender: sbj.ml.read@gmail.com X-Host-Fingerprint: 209.85.223.173 mail-ie0-f173.google.com Received: from [209.85.223.173] ([209.85.223.173:40357] helo=mail-ie0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/01-21228-92748A45 for ; Sat, 03 Jan 2015 14:46:50 -0500 Received: by mail-ie0-f173.google.com with SMTP id y20so17793996ier.4 for ; Sat, 03 Jan 2015 11:46:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=PRi7rPqZRhmEflAEepvP+fpdEjJ/QYBinic2B+uJDDI=; b=lLg3zlyfIXzl0h10/1uKTC2//Ck8L2Ld13WJmw38bmJRQvfTG7roPcctmdkHeRtcot blRlETbI6QiXfCuEeKtgEnBEYs95TbENKTLhlLSO2Ruh0SuVONmKMjBZDPnTQ6UMStxV jAkPNzev+uuN4ACjyHHDt0l6QR9RJzGA2gLzEmdG8O8X9vDpnuYgmHMzWf76paYftcdq uX9W2QZ9UTH9IQTChdEvq4fLEqPjXcbU2tq2rTjFaH00T/lFQNHmqj9hIv0g9DCssSBS PwMTw64nF55IPMDirNhzrHXAn43NlLDCEb7XmD3ojKkAYzY0TtIpCWkLVrAKgpdtwNUT T1Ug== MIME-Version: 1.0 X-Received: by 10.43.75.69 with SMTP id yz5mr62023595icb.90.1420314407193; Sat, 03 Jan 2015 11:46:47 -0800 (PST) Received: by 10.107.44.82 with HTTP; Sat, 3 Jan 2015 11:46:46 -0800 (PST) In-Reply-To: <360F9366-07C2-4C7A-AC3C-D482AFDD9838@ajf.me> References: <41D5BB0B-73AF-488E-968D-90B2878E3178@ajf.me> <360F9366-07C2-4C7A-AC3C-D482AFDD9838@ajf.me> Date: Sat, 3 Jan 2015 20:46:46 +0100 Message-ID: To: Andrea Faulds Cc: Pierre Joye , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints From: sbj.ml.read@gmail.com ("Sebastian B.-Hagensen") >> - on-numeric strings not accepted. Numeric strings with trailing >> characters are accepted, but produce a notice. >> >> I would rather not allow fancy conversions here. Any trailing non >> white spaces characters should not be allowed. I know it is not what >> PHP does now in some cases but this is really a fuzzy area and never >> really matched any actual needs or usages. > > Yeah, I don=E2=80=99t like this behaviour much. I want to avoid inconsist= ency with the behaviour of extension functions (i.e. zend_parse_parameters)= where possible, though. Since this has come up so much, I should probably = make an RFC to change this aspect of ZPP=E2=80=99s behaviour. That RFC should probably be voted on before this RFC proceeds into voting. After skimming through the RFC I'm unsure what the following code would pro= duce: function test(int $a, int $b) {} test("10.4", 10.6); If a warning/notice is raised, fine. If it will just result in $a =3D=3D=3D (int)10 && $b =3D=3D=3D(int)10 : I agree that consistency is a sound reason for this behavior. However type annotations (or whatever they will be called) should not only ensure that a parameter has a certain type but that no data was lost during the conversion. It is reasonable (assuming the target type can handle the value) and fine to convert an integer into a float, a float/integer to a string or any string that would satisfy is_numeric into a float (or if no data was lost an integer) and hide it from the developer (after all, that is was php is about). If a conversion might result in data or precision loss the developer should be notified with a hard failure. (E_RECOV, E_WARNING, I can still chose to ignore them using error handlers or error_reporting settings). Allowing data (I would also consider (string)'12a' =3D> int(12) data loss) or precision loss while converting a typed parameter would reduce the usability of the whole addition. If I'm in a situation where data loss is acceptable I could just leave the annotation away and cast as I would've always done or not cast and trust on php to do whatever is required. However caring about data loss in these specific occasions( including the string -> int example above) would forbid me to use type annotations. As I would have no way of knowing and bailing out if the original value was altered before it was accessible by my code. If type annotations wouldn't go beyond the safety that php currently provides by converting in specific contexts and casting what is the benefit in adding them? However, while I see issues with the RFC (that might be related to a misunderstanding on my side) I like the general direction. >> I am also not a fan of errors, exception, at least for methods, make >> much more sense. I know it is relatively easy to handle errors as >> exception but still, let do it right now. > > That=E2=80=99s be inconsistent with our other type hints. To get this cha= nged, I think we=E2=80=99ll just have to wait for Nikita=E2=80=99s Exceptio= ns in the Engine for PHP 7 RFC.