Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76001 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72338 invoked from network); 24 Jul 2014 10:11:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2014 10:11:13 -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.216.51 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.216.51 mail-qa0-f51.google.com Received: from [209.85.216.51] ([209.85.216.51:59274] helo=mail-qa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/42-58899-FBBD0D35 for ; Thu, 24 Jul 2014 06:11:12 -0400 Received: by mail-qa0-f51.google.com with SMTP id k15so2670748qaq.10 for ; Thu, 24 Jul 2014 03:11:13 -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=Nr/tG+tQ3ZGAjnKoz0PoCyD8ooGe/cijhLL3ixPQyPw=; b=yGlUSZsw6Fhdn+/2GgHIVwQt18LfywtJ4A6zCHoLIvJiATVmIFEzllhiNg75fl4Ifh A254OxtYrYyq/PP+uHxLfGgZ31wed2DAuzn2ipibUlz6WBm/amrs9rowR9S963vIZg5T pmpXxPAs0sowgJ9YFnij9H7vpK3+DQv0L8140oHKTq00mIvIjtdsG4KldV26pNhPCWxZ fp7o4skGGDK6GmDsbW1+iYViit4jqujjVZR9Fcan5+3VF8BOeyjnZv4v9KgQ3JWzsIZv pt8KKxxUJjmEah0W94hVPidQGUqvJnjGcZODJ4OF4zCbMovdfJ+vEuGGtrWZG4C+CtQv fxZw== MIME-Version: 1.0 X-Received: by 10.224.137.193 with SMTP id x1mr13956975qat.0.1406196673120; Thu, 24 Jul 2014 03:11:13 -0700 (PDT) Received: by 10.140.24.54 with HTTP; Thu, 24 Jul 2014 03:11:12 -0700 (PDT) In-Reply-To: References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <12448510.rPWIJSKt4t@rofl> Date: Thu, 24 Jul 2014 12:11:12 +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 11:03 AM, Pierre Joye wrote: > 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. and to clarify this, after I got some questions/comments on irc etc.: f.e. foo(int $a) { var_dump($a===123); } foo(123) >> true foo("123") >> true foo("123a")>> error, bad arg same for float. The cast happens, it would not make sense if not :) Cheers, -- Pierre @pierrejoye | http://www.libgd.org