Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82916 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92314 invoked from network); 17 Feb 2015 01:57:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 01:57:34 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.217.178 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.217.178 mail-lb0-f178.google.com Received: from [209.85.217.178] ([209.85.217.178:33380] helo=mail-lb0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/23-08417-E00A2E45 for ; Mon, 16 Feb 2015 20:57:34 -0500 Received: by lbvp9 with SMTP id p9so1828243lbv.0 for ; Mon, 16 Feb 2015 17:57:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ZM9JSjXC3xGYxJZZPH3GbRFzPDoYqIJlueFEBv2irzQ=; b=IQApybs86XLZwlhdew+Vy8X2u8+FglTS3mo6Tk2s1r/1PSEFOqDx7ohkytwuC3X64s xXew4NXGK99MQy8ernCq9P2jhZo3APuxk44SU7yGWMQHa8SOZQruuTaC22DPZpTxasKM pi6WGeDuhUzokUaTuCDko9hjupT6ntZbfsX9ARxtJhuuqnuCBgUBaWZCVbNGr18YeQng 36eKXpVO3ai63n0elslF+KqjG1pCFuNXGSS+yAFQEUYbA1qhjxxiUEMkffKzJHuHB+qD 2GnWGmZ7/K0SJvByzU6a1gIUc0iWI6fllS/GyRC+JHPRfoLIv2WRcLtq60YsiuejYBXz ejGw== X-Gm-Message-State: ALoCoQkPCw+8UlKOCnA2YpM2Vom3ZpyGNtLLDmc202fEYg+/zRQ4ga9a9B2Clh4bE3AeycvHz5M/ MIME-Version: 1.0 X-Received: by 10.152.19.194 with SMTP id h2mr26780444lae.77.1424138251151; Mon, 16 Feb 2015 17:57:31 -0800 (PST) Sender: php@golemon.com Received: by 10.112.126.65 with HTTP; Mon, 16 Feb 2015 17:57:31 -0800 (PST) X-Originating-IP: [199.201.64.2] In-Reply-To: <54E290E5.3020508@lerdorf.com> References: <011801d04a07$83ab1c00$8b015400$@php.net> <016f01d04a3a$e9183220$bb489660$@php.net> <54E290E5.3020508@lerdorf.com> Date: Mon, 16 Feb 2015 17:57:31 -0800 X-Google-Sender-Auth: cpKKS8p1AsywqjiZVLoDpCVy5tc Message-ID: To: Rasmus Lerdorf Cc: francois@php.net, Philip Sturgeon , Arvids Godjuks , Jefferson Gonzalez , Rowan Collins , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Reviving scalar type hints From: pollita@php.net (Sara Golemon) On Mon, Feb 16, 2015 at 4:52 PM, Rasmus Lerdorf wrote: > I still disagree strongly that it serves everyone's needs. The internal > API and APIs provided by extensions are completely messed up by this > approach. Userspace authors get the choice when they write their code. > Even if the caller has turned on strict, if you haven't added strict > types to your functions/methods you are fine. Internal API and extension > authors don't get this luxury. If the caller turns on strict, then > suddenly an API that was written explicitly to make use of the coercive > characteristics PHP has had for 20+ years breaks and there is nothing I > can do about it as an extension author. This is beyond just int->float > coercion, which is, of course, also missing. > It's not your problem how a script author choses to use your function. Is it a bug in PHP that currently I can call number_format() with an object? No. number_format() was written to take a float, and accepts ints and numeric strings as a byproduct. Adding the option on a per-file basis to make that call strict doesn't change the intent or the usage of number_format(). number_format() still gets a float and still acts on that float in the same way. All that changes is whether passing an int or a numeric string is considered "wrong" or not. We can sigh and tut about this not being "the PHP way", but the script author was the one who chose to enter into a tight contract, and the script author, not you, is the one who should have that authority over their own application. > And how do you think users will deal with internal functions that are now > suddenly strongly typed even though they were not designed to be? > I think they'll deal with it by dint of having /chosen/ to turn on strict typing. It's not as though an upgrade to PHP 7.12 suddenly made all their code strict without warning. In fact, nothing will have changed for them at all UNLESS THEY EXPLICITLY ASK FOR IT. > Do you think they will go look at the source code for the function and mimic > the data sanity checks and put those in their userspace code? > No, they'll look at their own code and make a more informed decision than any extension author can make for them. > Out of the 3 scenarios, this is inarguably the worst outcome with the > last line there being the most blatant. Actually outputting an internal > resource id as if it was a valid number to be formatted without the > slightest notice or warning anywhere that something is wrong in the code. > Again, you're assuming a single method call in a vacuum. Is it possible that the kind of script author who is turning on strict typing might, in fact, be strict in the rest of their application? Might, in fact, not try to pass a resource into a function expecting float because they have the tools of strict typing available to them? > This is my fear with this approach. People will start littering their > code with casts and it will hide real bugs which is the complete > opposite of what motivated this in the first place. > So let's talk compromise. Would leaving internal functions out of the picture at this stage change you mind? This is effectively what Hack does, internal functions are explicitly marked as "coercible". Would a tri-state option make sense? ('weak-all', 'strict-user/weak-internal', 'strict-all') How do we get from here to something you would like? > Without more thought into how we properly deal with internal/extension > code I don't really understand how so many people foresee this to work > perfectly in the real world. > This would be an opportune time for me to quote you as saying you're really not that into languages. :) As I said above, I foresee this working well in the real world because nobody is acting in a vacuum, there's an entire application's worth of type-checked code going into it. -Sara