Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70014 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25323 invoked from network); 5 Nov 2013 13:15:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2013 13:15:21 -0000 Received: from [127.0.0.1] ([127.0.0.1:26958]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 7E/F2-04169-96FE8725 for ; Tue, 05 Nov 2013 08:15:21 -0500 Authentication-Results: pb1.pair.com header.from=ua.oleg@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ua.oleg@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.54 as permitted sender) X-PHP-List-Original-Sender: ua.oleg@gmail.com X-Host-Fingerprint: 209.85.128.54 mail-qe0-f54.google.com Received: from [209.85.128.54] ([209.85.128.54:57822] helo=mail-qe0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 57/F2-04169-FBCE8725 for ; Tue, 05 Nov 2013 08:04:00 -0500 Received: by mail-qe0-f54.google.com with SMTP id 1so4993363qec.27 for ; Tue, 05 Nov 2013 05:03:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=1+dmOdbC5m6g5vxa3zvvgkE5+FB8tMZ/Dk/AHipX1UY=; b=clitBzCGPz5nEQm76pvD1oOLJFm3eAvfMDsvNjiVQrndOXVD+LE3yfd1ifjDWlsVCZ WWjhJhwSG6xfxfcZ0DAoxvI0celLE2mSevb7FfsuF90ubNYVYIm2c9op1V5qMpkb3sBw 5mersgDU7VQvD1J3ZkLobFMtPEDYa1aZS2R5KuE+0qdV85EBuCcRxg0NjHADDy1u3Pru v7e1vfp593RcTjBUdEV0zX185rqaNkZevUb8UUnyMTslji5nvB5L4bnLIKcE4JPhAjt2 QDpnEUxuN6mVnBWExilWKZH604/04eiGdtLVOFpa89dLgW9+G9cAbD6uyenmVJeQU+Il vejw== X-Received: by 10.49.103.161 with SMTP id fx1mr28893394qeb.68.1383656637592; Tue, 05 Nov 2013 05:03:57 -0800 (PST) MIME-Version: 1.0 Sender: ua.oleg@gmail.com Received: by 10.224.21.71 with HTTP; Tue, 5 Nov 2013 05:03:37 -0800 (PST) Date: Tue, 5 Nov 2013 15:03:37 +0200 X-Google-Sender-Auth: UsjpMGqrvl2zLbDh0bk6qivd7F0 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=047d7b2e466a5ffa4e04ea6daa4a Subject: PHP RFC: Deffering functions by arguments (count or/and type) From: oleg@poludnenko.info (Oleg Poludnenko) --047d7b2e466a5ffa4e04ea6daa4a Content-Type: text/plain; charset=UTF-8 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 --047d7b2e466a5ffa4e04ea6daa4a--