Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83536 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39121 invoked from network); 23 Feb 2015 02:59:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2015 02:59:55 -0000 Authentication-Results: pb1.pair.com header.from=jgmdev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jgmdev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.48 as permitted sender) X-PHP-List-Original-Sender: jgmdev@gmail.com X-Host-Fingerprint: 209.85.216.48 mail-qa0-f48.google.com Received: from [209.85.216.48] ([209.85.216.48:36768] helo=mail-qa0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0D/38-33016-9A79AE45 for ; Sun, 22 Feb 2015 21:59:55 -0500 Received: by mail-qa0-f48.google.com with SMTP id dc16so20338625qab.7 for ; Sun, 22 Feb 2015 18:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=zBmmPBUxjKPzfgn7sXEWDyiIxo2cwmi6VoMhQ5fjrqI=; b=kcVVKqUr6DCQL63h4XaZcH1Wotjf8EDGp5aFlPEYGNKLdO1uDAwVjve4zFzML+o8QB yY1fG4lVjElMJ9bwb+eW6oQAx5CxHce4bPzfewsW979wtiNXGb/FTn9DglRh0R6kJPIQ eIrsqsxZz374WuUuAGXWAF7oaibp5g6QaTW9vS/MTutH1mi1PNGIojq4QAR9jPXRaYgV mw4de4Bj1GuVD6h4vF/ghd/p+piXMqM/WTVuE5XwglnIpJxWwin76/3FaKSSHDAOejZk QFJACwL8DnzvwXzQ3PG/lsUYbgvJi+OjagIecK3439TvDxbVmc63Ps0rxmJ5ULr9MngX 59Og== X-Received: by 10.140.42.13 with SMTP id b13mr18539534qga.43.1424660390594; Sun, 22 Feb 2015 18:59:50 -0800 (PST) Received: from [192.168.1.109] ([24.138.231.2]) by mx.google.com with ESMTPSA id i185sm16660927qhc.18.2015.02.22.18.59.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Feb 2015 18:59:49 -0800 (PST) Message-ID: <54EA97A2.4010701@gmail.com> Date: Sun, 22 Feb 2015 22:59:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Zeev Suraski , Jefferson Gonzalez CC: PHP internals References: <2e4694f9805ee81ea0b2c79eab06c2d6@mail.gmail.com> <54EA5EDA.8010605@gmail.com> <54EA6A99.5010609@gmail.com> <54EA7F15.9030606@gmail.com> <54EA891B.6030405@gmail.com> <09b9ee836c04b1750614a91bd39a5bed@mail.gmail.com> In-Reply-To: <09b9ee836c04b1750614a91bd39a5bed@mail.gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC) From: jgmdev@gmail.com (Jefferson Gonzalez) On 02/22/2015 10:06 PM, Zeev Suraski wrote: > One key premise behind both strict type hinting and coercive type hinting is > that conversions that lose data, or that 'invent' data, are typically > indicators of a bug in the code. > > You're right that there's no risk of a segfault or buffer overflow from the > snippets you listed. But there are fair chances that if you fed $x into > round() and it contains "whats cooking" (string), your code contains a bug. > > Coercive typing allows 'sensible' conversions to take place, so that if you > pass "35.7" (string) to round() it will be accepted without a problem. > Strict typing will disallow any input that is not of the exact type that the > function expects, so in strict mode, round() will reject it. The point that > was raised by Stas and others is that this is likely to push the user to > explicitly cast the string to float; Which from that point onwards, happily > accept "whats cooking", keeping the likely bug undetected. Thats true, but I think where most problems will rise is when dealing with user input, example: Good url myurl.com/?id=10 Bad url myurl.com/?id=somehing+else So in the url example neither coercive or strict are safe, IMHO you as a developer should analyze the input and decide what to do if the value isn't of an expected type. On strict you as a developer decide if casting is an accepted behavior, like when dealing with database output which may return values as string, or reading from config files, but you know the value is (int) compatible, so the casting is safe. Besides, in the v0.5 STH RFC the strict mode is optional. I think both RFC's should join, dual mode coercive/strict :), but I guess that will not be possible until Anthony convinces the coercive camp how strict could be used to do better optimizations. Unless it happens the other way around and is proved with code/patches that same level of optimizations can be reached with coercive. Anyway I just hope for scalar type hints, not just to improve code reliability, but also to gain some performance out of it. At the end I wish the best option is implemented since this is a really impacting feature for the future of the language.