Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70017 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49712 invoked from network); 5 Nov 2013 18:09:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2013 18:09:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.179 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.179 mail-ob0-f179.google.com Received: from [209.85.214.179] ([209.85.214.179:60188] helo=mail-ob0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/B1-40963-E6439725 for ; Tue, 05 Nov 2013 13:09:51 -0500 Received: by mail-ob0-f179.google.com with SMTP id uy5so8897019obc.38 for ; Tue, 05 Nov 2013 10:09:47 -0800 (PST) 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=QPiN9927hTKktmGwIm4q/Oq3xkopMTtLjHw1pa6OV3c=; b=mce3aZL9QAVEBk56acc57pQHb+BJwAa0ZQzCoNzlpJ00z3lMwgV7cl/Z8OjYF/Wzg0 meLUZ1R8aBcfHTDBp4wGu/myI4cO/5OXoVDBXwSAQMwrngTNvrZop3YzxqZ64599D4m1 fU0WlYxPk4PvqbW9DWU6SstlCMudWygWOX3gKZcntglCaVurAHMj9pDsJzEoVUnJBQqQ ciADqx7syQKcq5WYjXRRpKecmJMY8AOBDo4CYdvuL7J3Ht9CmiBdl30oXNToPrRoR26L cbIAhox2Fn0j8fDiCIoKRELbo3JRc2pFK8J+Py+CL/WFV/wOoNCzvftJIHjKpuHneu61 lLNQ== MIME-Version: 1.0 X-Received: by 10.182.166.40 with SMTP id zd8mr19615868obb.25.1383674987820; Tue, 05 Nov 2013 10:09:47 -0800 (PST) Received: by 10.182.54.112 with HTTP; Tue, 5 Nov 2013 10:09:47 -0800 (PST) In-Reply-To: References: Date: Tue, 5 Nov 2013 19:09:47 +0100 Message-ID: To: Oleg Poludnenko Cc: PHP internals Content-Type: multipart/alternative; boundary=e89a8ff1ce02224edc04ea71f0c3 Subject: Re: [PHP-DEV] PHP RFC: Deffering functions by arguments (count or/and type) From: nikita.ppv@gmail.com (Nikita Popov) --e89a8ff1ce02224edc04ea71f0c3 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Nov 5, 2013 at 2:03 PM, Oleg Poludnenko wrote: > Hi, > > My idea is somehow related to this one: Syntax for variadic > functions > It is not a competitive idea but a supplemental one. > > So, the main point is to write different implementations for the functions > with the same name, but with different of arguments count or/and type: > > class Config { /** * Returns property value * @param string $key * > @returnmixed */ > public function prop($key) { return isset($this->prop[$key]) ? $this->prop[ > $key] : null; } /** * Sets property value * @param string $key * > @parammixed $value *@returnConfig */ > public function prop($key, $value) { $this->prop[$key] = $value; return > $this; } } > > Also it will be possible to change arguments during inheritance: > > class Figure { /** * Calculate perimeter of an arbitrary figure * > @paramarray $angles *@returnint */ > public function calcPerimeter(array $angles) { return array_sum($angles); } > } class Square extends Figure { /** * Calculate perimeter of a square > *@paramint $angle *@returnint */ > public function calcPerimeter($angle) { return 4 * $angle; } } class > Rectangle extends Figure { /** * Calculate perimeter of a rectangle * > @paramint $height *@paramint $width *@returnint */ > public function calcPerimeter($height, $width) { return 2 * ($height + > $width); } } > > The advantages of the syntax are: > > - It's immediately clear what function implements. > - The function becomes cleaner, without a lot of if-else constructions. > - A great opportunity to change function arguments during inheritance. > > > Regards, > Oleg Poludnenko > Would you mind putting your code in a gist/pastebin (or re-sending the mail with proper formatting)? It's hard to understand what this is about when the code is all in one line :) Nikita --e89a8ff1ce02224edc04ea71f0c3--