Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80094 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70950 invoked from network); 2 Jan 2015 14:01:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jan 2015 14:01:52 -0000 Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 74.125.82.179 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 74.125.82.179 mail-we0-f179.google.com Received: from [74.125.82.179] ([74.125.82.179:38886] helo=mail-we0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/A1-61219-FC4A6A45 for ; Fri, 02 Jan 2015 09:01:52 -0500 Received: by mail-we0-f179.google.com with SMTP id q59so4523070wes.10 for ; Fri, 02 Jan 2015 06:01:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=mlWuoOdeS25wavuv4E2xiAXKdgdBwUAR4VipPM1vZcI=; b=UYs+prnnd9TgHTsHea95sE4vMraXTVR5LZ/bWwCga/eAmJEfJNO8QPoMNBd+G9ZOXS jD+c0nRZWkTEx0ED12eHcW+3alSQu/vFc8kaCgtq627Dh4aH7xK+LVTJH/TDQKHz99ns qz6yRY2Lg3PslZ+Pq2PRHTUp+JEgpnkGAKt3WEZ5kA+l7FYbTWC3WUtuP7cONTFg3zW8 Ubw80uS1Vg71uhVqILimKJnVAKnJNUb3ezE5KqXJv4HleiOTTGhg2f41BBPWMpuL238/ MSPHlIrtDEF0YtmUtWpU/7GEBoDmDX5Zp0YjBmKIPYpbfYmQktBrf/mVNQnbKKWpJhZ0 K51g== X-Gm-Message-State: ALoCoQmGIRnzHtiIfVXHFrXhsoYv0zlO9s2V6k4f9gGAWlw1n4bo74jDSmY5QlurLupMxh1hd0+g X-Received: by 10.194.62.19 with SMTP id u19mr152903722wjr.0.1420207308578; Fri, 02 Jan 2015 06:01:48 -0800 (PST) Received: from [192.168.0.169] (90.31.14.46.dynamic.wline.lns.sme.cust.swisscom.ch. [46.14.31.90]) by mx.google.com with ESMTPSA id ud4sm54246845wib.0.2015.01.02.06.01.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jan 2015 06:01:47 -0800 (PST) Message-ID: <54A6A4D3.9070808@seld.be> Date: Fri, 02 Jan 2015 14:01:55 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: internals@lists.php.net References: <41D5BB0B-73AF-488E-968D-90B2878E3178@ajf.me> <54A5DF14.7000105@gmail.com> <54A678EA.4070706@fischer.name> In-Reply-To: <54A678EA.4070706@fischer.name> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints From: j.boggiano@seld.be (Jordi Boggiano) On 02/01/2015 10:54, Markus Fischer wrote: > On 02.01.15 05:36, Levi Morrison wrote: >> I don't necessarily have any more insight to provide than has already >> been done, but I do want to chime in and say that I personally favor >> strict types as Nikita Popov has been advocating. > > Same from me. I support all arguments so far made by Nikita; they're > well laid out, better than I could have done it. And I, on the other hand, disagree. Looking at it from an OSS maintainer perspective, introducing strict hints in code would be a huge BC break as I don't know how people use my code, nor if they validate/coerce their user input early or not. If I suddenly declare something as int and someone used to pass '5', they get an error. That would make adoption quite hard in OSS IMO if you don't want to bother people. With weak typing on the other hand, I get to remove tons of @param annotations which would be amazing, and I get additional safeties that *new* mis-uses (like passing an object in an arg expecting a string, which at the moment could not be type hinted) will be caught early in the future. Existing mis-uses probably don't exist much since they'd likely fail further down in the code execution already, but in case they don't they'd be caught too and that's a good thing since it makes people look at their buggy code. As for valid uses of the code, like the '5' above, it keeps working just fine because it is fine. It's not my call as a library author to decide whether the users of the lib should cast user inputs to ints or validate them or do nothing at all. Besides, IMO if strict typing was so desirable we would see more of the String/Int classes out there, or we would see people do things like: function foo($number, $string) { expectNumber($number); expectString($string); } That'd be a simple lib to write, it barely adds more code to your functions, and you get strict typing. But I hardly see anyone do this, and I would argue it's because it sounds appealing in theory but it's not worth it in practice. Cheers -- Jordi Boggiano @seldaek - http://nelm.io/jordi