Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82984 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89566 invoked from network); 17 Feb 2015 16:38:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 16:38:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.217.169 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.217.169 mail-lb0-f169.google.com Received: from [209.85.217.169] ([209.85.217.169:39732] helo=mail-lb0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/54-19463-C9E63E45 for ; Tue, 17 Feb 2015 11:38:52 -0500 Received: by lbvn10 with SMTP id n10so5524241lbv.6 for ; Tue, 17 Feb 2015 08:38:49 -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=1y2G/5Qbvy7gtx9jCJ/2NGjmDTPgvQIIiqzfP8K5jiw=; b=V+oSJ2d163+IWVuGissiZ5DI86U+RZMeRFkbJDwDOTd49omWeLWFhMJWgr+xZ0SrYO B0R7Akk+jlAkmGC9nkClzZBopjWUg3PYRPrU9KoRNQO8UXdfQLjsoJNlBxc7YIB2li+5 tuY1C8BN5i+9RlZPcf1/wwuRxKxEH12jzbiYUp4L29InK+awViyIsLHVtZb9+A/WIuhu cF5qgRMIdiJ855TeV64K5H+OYNq2cdy2Dfzx0Tm1cr5lgy0TgNr0HFx4W/Nufq0sMvDm /KBysuvnFqZvch4KsEARaefTjaNnD8b6dCtOIu3ZZIzbMMdYI8eDJtADPQnvzgiR8qm9 XiZQ== X-Gm-Message-State: ALoCoQlG5xdTlmHVguKPiWHDEqfEETNxIEGM+EdleaxanQuDAHhHDGiSxsAlXXvoDjnq3tj6kQgg MIME-Version: 1.0 X-Received: by 10.112.235.10 with SMTP id ui10mr13661962lbc.77.1424191129153; Tue, 17 Feb 2015 08:38:49 -0800 (PST) Sender: php@golemon.com Received: by 10.112.126.65 with HTTP; Tue, 17 Feb 2015 08:38:48 -0800 (PST) X-Originating-IP: [199.201.64.2] In-Reply-To: <54E2FA57.6050009@lerdorf.com> References: <011801d04a07$83ab1c00$8b015400$@php.net> <016f01d04a3a$e9183220$bb489660$@php.net> <54E290E5.3020508@lerdorf.com> <54E2AD88.6040206@lerdorf.com> <54E2FA57.6050009@lerdorf.com> Date: Tue, 17 Feb 2015 08:38:48 -0800 X-Google-Sender-Auth: a7Xdp07nxCudIXd5TwN0tvlTfK4 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 Tue, Feb 17, 2015 at 12:22 AM, Rasmus Lerdorf wrote: > On 02/16/2015 09:48 PM, Sara Golemon wrote: >> Second, I should clarify that while the HHVM runtime performs >> coersion, the hack type checker is strict. So my original statement >> was inaccurate. As far as hack is concerned, it's simply strict. >> Period. > > With both the default (partial) type checking and strict enabled, my > number_format() example in Hack produces: > > ... > > Please correct me here if I somehow ran these incorrectly. I did put > some deliberate type errors into my userspace code and hh_client caught > those nicely, so it seems like it was working, but it didn't catch > anything when it came to calling the internal API functions. > The mechanisms are strict, but the definitions, in hack, are untyped, so there's nothing to validate: hphp/hack/hhi/stdlib/builtins_string.hhi: function number_format($number, $decimals = 0, $dec_point = ".", $thousands_sep = ","); We left a lot of stuff untyped from hack's point of view precisely because so much of PHP's APIs are non-sensical. Have you looked at what chr() does with bad types lately? Yikes. > So, you keep asking what I would support. I would like to see an RFC > along the following lines: > > 1. Tighten up the type coercion for the "1000 dogs" case although we > have to look at whether there is a problem with some database APIs > returning space-padded fields so "1000 " would now break. > Hopefully that is fringe enough to not break the world. > Hopefully, though I think that we could embrace the idea of trailing space as insignificant. > 2a. In strict mode, tone down the strictness and allow non-lossy > coercion including int->float. And yes, I know in really edge cases > that isn't technically non-lossy, but for all practical purposes it > is. > Nod. Ze'ev called for this too. > 2b. A much more flexible system for specifying multiple types. I should > be able to say that my function takes something that looks like a > number if I choose and still take advantage of stricter typing for > other parameters. > Union types. I'm hear a lot of support for this concept, and not exclusively from one camp. Perhaps with a psuedo-type defined somewhere to account for the half-type "numeric string". > 3. Don't turn on crazy-strict mode for internal functions that weren't > designed for that. Instead provide the same ability as userspace gets > for developers to gradually design their APIs to be stricter if they > so desire allowing both Hack and PHP to implement a stricter > curl_setopt(), for example. > Perhaps a ZEND_ACC_STRICT flag which lets an API opt-in to strict mode? Or something passed to the arg_info struct? The details are secondary, but you get my meaning... -Sara