Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75999 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65518 invoked from network); 24 Jul 2014 09:03:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2014 09:03:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.51 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.192.51 mail-qg0-f51.google.com Received: from [209.85.192.51] ([209.85.192.51:63204] helo=mail-qg0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/21-58899-9EBC0D35 for ; Thu, 24 Jul 2014 05:03:38 -0400 Received: by mail-qg0-f51.google.com with SMTP id a108so2803536qge.38 for ; Thu, 24 Jul 2014 02:03:38 -0700 (PDT) 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; bh=MOC4ojjVCq9LTsojpzu1xKeIxu0nCaFxk+ZXimcEqUE=; b=rSo81yl4O/pCa2N7McK0e9fP6aAQLfENvYHzwRgPlP7f5Zl/dz1n52jXYC/6BjkZsL mVdenco95VK7B87HV8ZhxprX8posw9eCmQEkNvN+1Ksh1K7Fie+1GXE7Vc+8YR6Jn52h XHNkQx0zrqHXU9ZJs20kSQRhG3U55hvSDyneQFMy34drOXy3o8dSi+fasn8ncEyW+6SJ HidWHDfqf9KGuJAuAjHhbjt0Wvy3w+xt8jaI4sFfQ5QrGK7HXZ59hOPpgY6XI831qWAh W6wG18XI83sOVsVygiAd0THqQcxkG+JMHbHgYvFe6WH6b0yZF99dOuTEt4XYrbd3ru/S hEpA== MIME-Version: 1.0 X-Received: by 10.224.8.5 with SMTP id f5mr11290390qaf.87.1406192618068; Thu, 24 Jul 2014 02:03:38 -0700 (PDT) Received: by 10.140.24.54 with HTTP; Thu, 24 Jul 2014 02:03:37 -0700 (PDT) In-Reply-To: References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <12448510.rPWIJSKt4t@rofl> Date: Thu, 24 Jul 2014 11:03:37 +0200 Message-ID: To: Patrick Schaaf Cc: PHP internals , Andrea Faulds Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: pierre.php@gmail.com (Pierre Joye) On Thu, Jul 24, 2014 at 10:52 AM, Pierre Joye wrote: > On Thu, Jul 24, 2014 at 10:42 AM, Patrick Schaaf wrote: >> Hi, >> >> there is, it seems, something missing from both the RFC and the >> discussion, as far as I read it. Sorry if it came up before, it was a huge >> amount of mails... >> >> How does the proposal affect method compatibility between >> subclasses and baseclasses? Will two methods there, differing in the >> scalar type annotations of one of their arguments, elicit STRICT >> warnings, like object type annotations do? > > I think it should behave like class arguments do. I should be more precise :) say: function i(integer $i) function f(float $f) function s(string $s) $i = 12; $f = 1.234; $s = "abcdef"; For integer arguments: Works: i($i); Fails: i($f); i($s); i(new StdClass); float fails as the argument cannot be an integer without lost of information. It is a mis-usage of this function argument and the intend of the caller can only be guessed and can only lead to bugs. For float: Works: f($i); f($f); integer is, if I take the class behavior as example, like a float, same "interface", fully compatible. Fails: f($s); i(new StdClass); For string, every scalar should work as both float and integer are easily converted to string, we can compare them to objects with a __toString method. I could live with strict too here but implicit string conversion makes sense here. Float precision setting is used for the decimal precision. Arrays and objects without __toString fails, obvioulsy. Cheers, -- Pierre @pierrejoye | http://www.libgd.org