Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92811 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25158 invoked from network); 26 Apr 2016 17:55:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Apr 2016 17:55:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.65 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.65 mail-lf0-f65.google.com Received: from [209.85.215.65] ([209.85.215.65:34117] helo=mail-lf0-f65.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/08-20013-49BAF175 for ; Tue, 26 Apr 2016 13:55:33 -0400 Received: by mail-lf0-f65.google.com with SMTP id m101so3529847lfi.1 for ; Tue, 26 Apr 2016 10:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=yDBj3XKTeylJx8Ej2F5piQskM9fJeVtIYPk+aSNRyIw=; b=Q/2U/UvKUJzmqqoCrV2cp+XdqrV7Eea9z+gZtfwRYzprsCHji04V54Ko6n0YdJMDiT vh5OgJeT0vIkgIf+IDFmtgnJtgTHywR46qVfqls+zz0pKQls/0f8Sv26D5QYaw919tBM wERHJKCX5qmE0RPvgqULu2lAFHpwwYeY+fC18FBBN3o6/TyacMHSDipNmaOVeK/ZHyyg y+rcSdna98jzC8xt34ciRJAsmodesEUVJNTPWcGnwkAIy2sm6osDYuyUucDbBwHUkXzb 5IxrbDw2NvISf/xcjRwcPvqP3y54SXdfV/SoT00r2QxJReroGtJkk35KHd8td2kl4Kng y++A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=yDBj3XKTeylJx8Ej2F5piQskM9fJeVtIYPk+aSNRyIw=; b=Irq7SGBJwAZ5vXHyKTJMmumn8RY/tKbQl2Bd9Jg+jkFpRiiyDZU9sE0NRyqiCL7NsS EVe7pcV408yKucdgf6b+6+wudPkm+ZZqfE/caNyCICZyiOfzo3paFup1vVdjjhBUlc3q siiXkYhDFUWUh4NiMFfCT7JgLrAqSLW7qjLmkxMKuO87I/7rQrLDr1JY1yBG1fKoUTG5 0IGca1wgtveyyFKZq8rU7DQ5Vh4q0jK669mxhsNAihN2xSkfi/r8JM3oXuUhCyWHPhdK chqTR20OilP8g/Dl6c7QAQNUNMrDjeQlXgMtx5DPj5s0O7NBwMd2lXip9ejU9m0sxSLC pirA== X-Gm-Message-State: AOPr4FXl9aYEy3cnNJaorrGNkqZX1Y1celha58FZWaAVVhoqg9FZuCoJdCHxtv03t+CjuQ== X-Received: by 10.25.22.193 with SMTP id 62mr1859698lfw.117.1461693329555; Tue, 26 Apr 2016 10:55:29 -0700 (PDT) Received: from nikita-work-box ([185.62.192.230]) by smtp.gmail.com with ESMTPSA id s63sm29481lfs.17.2016.04.26.10.55.28 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 26 Apr 2016 10:55:28 -0700 (PDT) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Jesse Schalken" Cc: "PHP internals" References: Date: Tue, 26 Apr 2016 20:55:20 +0300 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.16 (Linux) Subject: Re: [PHP-DEV][RFC] Callable Types From: inefedor@gmail.com ("Nikita Nefedov") On Sat, 23 Apr 2016 20:44:27 +0300, Jesse Schalken wrote: > I see. So it's the combination of not erroring when more parameters are > passed than a function accepts, and >permitting methods to add extra > optional parameters that is wrong. So without the former being > fix/deprecated, >the correct thing to do is to disallow extra optional > params. Makes sense. > > Are there any valid use cases for passing extra parameters to a function > any more, now that there is the varargs >syntax to replace > func_get_args()? If not, maybe it could be deprecated by this RFC. > > Regarding references, by-ref invariance for parameters makes sense, and > is what method compatibility does. >According to method compatibility > and call-time behaviour however, return by-ref is effectively a subtype > of >return by-value: > >> function &returns_ref() { >> $f = 0; >> return $f; >> } >> >>>> function returns_val() { >> return 1; >> } >> >>>> $v1 = returns_ref(); // ok >> $v2 =& returns_ref(); // ok >> $v3 = returns_val(); // ok >> $v4 =& returns_val(); // Notice: Only variables should be assigned by >> reference >> >> interface Methods { >> function &returnsRef(); >> function returnsVal(); >> } >> >>>> class ReturnRef implements Methods { >> function &returnsRef() {} // ok >> function &returnsVal() {} // ok >> } >> >>>> class ReturnVal implements Methods { >> function returnsRef() {} // Fatal error: Declaration of >> ReturnVal::returnsRef() must be compatible with >>& >> Methods::returnsRef() >> function returnsVal() {} // ok >> } > > Otherwise it LGTM > > cheers Hey, sorry for slow reply, been busy working... I don't really see use cases for func_get_args any more, variadics do it better (more obvious/documentative for the caller). But this is a huge BC break, I'm afraid it could be deprecated only in 8.0 and still that would be pretty big of an event... Definitely a matter of another RFC. You're right about return references, I've made changes in the RFC about it. There's a problem with syntax though. So now passing a function that returns a reference to a parameter that expects value returning function is working. But you can't declare in the callable typehint that you only need functions that return reference. That is, apart from syntax limitations, I'm always happy to discourage usage of references :P Touching optional parameters again - there was also my oversight, actually passing function with optional parameters is fine *as long as they are not typed*. Otherwise it can lead to weird type errors. So that was changed as well. Thanks to 3v4l guys, all these changes are on https://3v4l.org/ already, you can check them out :)