Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70018 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51762 invoked from network); 5 Nov 2013 18:22:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2013 18:22:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=ingwie2000@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ingwie2000@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.83.41 as permitted sender) X-PHP-List-Original-Sender: ingwie2000@googlemail.com X-Host-Fingerprint: 74.125.83.41 mail-ee0-f41.google.com Received: from [74.125.83.41] ([74.125.83.41:64228] helo=mail-ee0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/32-40963-67739725 for ; Tue, 05 Nov 2013 13:22:46 -0500 Received: by mail-ee0-f41.google.com with SMTP id e53so2031642eek.28 for ; Tue, 05 Nov 2013 10:22:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=HdnojEPkhGJhCmRtBW1DO5UJ6zEngPJZp/otPILtGvY=; b=U/gywHeKuLrFynhHlrkMkG4zP8YHVkNtUox2axNIZ+NndyveEtzIDUb3EmTY8EOXrK DkndMXD4AYlSKMBu7PxBokEGnVQeRNvSkKQ9izDRIMfrWWejD+ShhXyNmJLEcjhNxMvL Ck/7PAYT28lTvG0sPBhZZ/Whhv9A0YNwuOEd5zZVpaNgAf+KyIjVscF7a1VIoqfLdjhJ zZ/G1aWupbcfxeGkPcWrUSXGiarjyHoHDKqUtMXPRB2pVKO61mcb4hoiiPWJaki03Umu VpclSwO8XJv50uEJrejPWy4UowluzK6KoiQxKcy2IQc+9Bxu/oDFQy7ZD7ZPyYz+Q/J7 J+UA== X-Received: by 10.14.183.2 with SMTP id p2mr15058833eem.44.1383675763655; Tue, 05 Nov 2013 10:22:43 -0800 (PST) Received: from [192.168.200.19] (dslb-088-068-167-158.pools.arcor-ip.net. [88.68.167.158]) by mx.google.com with ESMTPSA id a6sm63326357eei.10.2013.11.05.10.22.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Nov 2013 10:22:43 -0800 (PST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1816\)) In-Reply-To: Date: Tue, 5 Nov 2013 19:22:41 +0100 Cc: Oleg Poludnenko , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Nikita Popov X-Mailer: Apple Mail (2.1816) Subject: Re: [PHP-DEV] PHP RFC: Deffering functions by arguments (count or/and type) From: ingwie2000@googlemail.com (Kevin Ingwersen) I had nothing to do, so here we go: = https://gist.github.com/IngwiePhoenix/e7fbee9f769fc137250d Am 05.11.2013 um 19:09 schrieb Nikita Popov : > On Tue, Nov 5, 2013 at 2:03 PM, Oleg Poludnenko = wrote: >=20 >> Hi, >>=20 >> My idea is somehow related to this one: Syntax for variadic >> functions >> It is not a competitive idea but a supplemental one. >>=20 >> 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: >>=20 >> 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] =3D $value; = return >> $this; } } >>=20 >> Also it will be possible to change arguments during inheritance: >>=20 >> 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); } } >>=20 >> The advantages of the syntax are: >>=20 >> - 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. >>=20 >>=20 >> Regards, >> Oleg Poludnenko >>=20 >=20 > 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 :) >=20 > Nikita