Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70015 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33600 invoked from network); 5 Nov 2013 15:28:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2013 15:28:26 -0000 Authentication-Results: pb1.pair.com header.from=ingwie2000@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ingwie2000@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.83.50 as permitted sender) X-PHP-List-Original-Sender: ingwie2000@googlemail.com X-Host-Fingerprint: 74.125.83.50 mail-ee0-f50.google.com Received: from [74.125.83.50] ([74.125.83.50:48867] helo=mail-ee0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/54-04169-89E09725 for ; Tue, 05 Nov 2013 10:28:25 -0500 Received: by mail-ee0-f50.google.com with SMTP id b45so1118633eek.37 for ; Tue, 05 Nov 2013 07:28:21 -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=aiMO6ORKw1AHm7PnSNBASy4wNW4pUt9Duhl2AZr/Yes=; b=X+VnvUbOkHBg9WLTL/MD3k8ccGuN/8KhV1oSFmJbDqmaJGKqHZg98BAu9bu6dPHrm1 jaVXJLk8NESQyGux1ruVOKuSikPbYIHnZZGQEgyuunfzs2MoqFwP/M9CStuuTwgwrYes +0Az4BR/OL783gvKfHzA8f9WGiwpEb6LIbaAm+tFaDHYdRxIqjeUyUaGRlPSeqYekp04 L0ANVLJ8lQ/fOLLFiSpxEKEmgEDXmQyZqyKCQ1sD+NErP+LQHQQwi2rEbpYrh5gpAIeJ 362kATrxqrzPcqBu/jpDjOV4D19FUCTv8ZfoMN0iafb1VMUs5q1URUaRY7/WEaM779So wFvQ== X-Received: by 10.14.203.198 with SMTP id f46mr561168eeo.111.1383665301743; Tue, 05 Nov 2013 07:28:21 -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 z2sm48820766eee.7.2013.11.05.07.28.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Nov 2013 07:28:21 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1816\)) In-Reply-To: Date: Tue, 5 Nov 2013 16:28:19 +0100 Cc: Developers List PHP Mailing Content-Transfer-Encoding: quoted-printable Message-ID: <29341BBD-F837-42CB-9607-796CCDC4EEE0@googlemail.com> References: To: Oleg Poludnenko 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) Hello there. You can actually do the first part using __call($methodName, array = $args). It's a little more complex to do that, but consider that as a = current solution. Alternatively, use func_get_args() inside your = function, or set the second parameter like method($arg1, $arg2=3Dnull) = and check if it is, or isn't null using if(is_null($arg2)), and then do = what the function should return on either scenario. I know, you are = listing these cases within your list of benefits, but one if is less = work than having PHP decide which "version" of the function you're = wanting to use - I bet it'd make the actual runtime slightly slower. The second part sounds interesting IMHO, but I somehow doubt it'd be = accepted. But we'll see. Kind regards, Ingwie Am 05.11.2013 um 14:03 schrieb Oleg Poludnenko : > 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