Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71364 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55376 invoked from network); 20 Jan 2014 22:06:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2014 22:06:00 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 108.166.43.99 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 108.166.43.99 smtp99.ord1c.emailsrvr.com Linux 2.6 Received: from [108.166.43.99] ([108.166.43.99:45558] helo=smtp99.ord1c.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/7E-02192-8CD9DD25 for ; Mon, 20 Jan 2014 17:06:00 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp5.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id 182F01B02BC; Mon, 20 Jan 2014 17:05:58 -0500 (EST) X-Virus-Scanned: OK Received: by smtp5.relay.ord1c.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id B157D1B02B2; Mon, 20 Jan 2014 17:05:57 -0500 (EST) Message-ID: <52DD9DC4.6060502@sugarcrm.com> Date: Mon, 20 Jan 2014 14:05:56 -0800 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Andrey Andreev , "internals@lists.php.net" References: <52D865C7.4070009@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > Please excuse my lack of knowledge, but if I understand this correctly, > this is how generics would work ... using arrays, ignore the syntax and > details such as child classes, interfaces, etc.: > > $fruits = Array; - declare that $fruits is an array that can only > contain instances of class Fruit > function eat(Array $apples) - function eat() will only accept > arrays that are declared in the same way as $fruits above There's two ways to understand "will only accept": 1. There's a class/type which I call ArrayOfFruit for simplicity. eat() checks if $apples is instance of ArrayOfFruit. Some magic inside ArrayOfFruit ensures ArrayOfFruit always contains only Fruit. 2. eat() goes over $apples which is a regular array, and checks if every element in it is instanceof Fruit. First way is essentially templates, second is not. So far I've seen most advocacy in this RFC to go towards the second way. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227