Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63578 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39135 invoked from network); 21 Oct 2012 11:24:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Oct 2012 11:24:19 -0000 Authentication-Results: pb1.pair.com header.from=dragoonis@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dragoonis@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.170 as permitted sender) X-PHP-List-Original-Sender: dragoonis@gmail.com X-Host-Fingerprint: 209.85.223.170 mail-ie0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:43666] helo=mail-ie0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/4E-22055-16BD3805 for ; Sun, 21 Oct 2012 07:24:18 -0400 Received: by mail-ie0-f170.google.com with SMTP id c12so2947837ieb.29 for ; Sun, 21 Oct 2012 04:24:15 -0700 (PDT) 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=yYw94oMU5oF0dAsu0SIEAHQyws6Xxq8zMh6BSxgjmh4=; b=O7nS+A0rpEQZ0JzOWvwaKyzTDwerpWCHRPiD4Gj87N6Faw/2CKhj16iSE8CmtH910V d0/eNJaVoKMWCdbbNM6yPE1SbE1jS1DWSJTyjysY9AvXc5twywdh5JxmZ5sL4Ij5jxNE KpW74SlCjiMEGX/XEz9wRWqgcWoIMy6dPcM20kOrpRL/6MHdyhRHgMI8BQOPaoCtxI1b XlRxy0RV5LlSnCR7QvfNxRkTjUWnxTVU0DoMiOlLM+mA0jVwMbiwNodEDwbl6ZYCLoeQ 4oq1q+rcJaG9qUc0SiCSslKuiYHwaHvatpXz7ISebdU5J5g5TjH8nJxMkqCLlOluXAJT FuDQ== MIME-Version: 1.0 Received: by 10.42.119.133 with SMTP id b5mr5328521icr.56.1350818654939; Sun, 21 Oct 2012 04:24:14 -0700 (PDT) Received: by 10.64.12.45 with HTTP; Sun, 21 Oct 2012 04:24:14 -0700 (PDT) In-Reply-To: References: <712F4499-949C-4C6F-A142-736A1B156189@gmail.com> <50831148.1070808@lerdorf.com> <6E76ACFF-FD5B-4BB9-8180-990D0156ECD6@gmail.com> Date: Sun, 21 Oct 2012 12:24:14 +0100 Message-ID: To: Nikita Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=90e6ba5bc23315687804cc8ffa46 Subject: Re: [PHP-DEV] Generics proposal From: dragoonis@gmail.com (Paul Dragoonis) --90e6ba5bc23315687804cc8ffa46 Content-Type: text/plain; charset=ISO-8859-1 Hi Nikita, What you're asking for is useful in other languages, but it doesn't match the style of PHP which is to be a quick and easy type-less scripting language. What you're proposing is clearly more suited to something like Java or C#, but doesn't really belong here. I'd also hate to see this anywhere near PHP. Many thanks, Paul. On Sat, Oct 20, 2012 at 11:10 PM, Marco Pivetta wrote: > On 20 October 2012 23:09, Michael Stowe wrote: > > > I see what you're trying to do but not a big fan of how it's being > > implemented in the example given. > > > > - Mike > > > > Sent from my iPhone > > > > On Oct 20, 2012, at 4:02 PM, Rasmus Lerdorf wrote: > > > > > On 10/20/2012 01:59 PM, Nikita wrote: > > >> Hello, list. I want to propose generics. For those, who don't know > what > > it is, here's example: say we have a Comment class, that has a method > > getBody. Also we have Collection class, that implements Traversable. Now, > > if I want to validate all insertions into collection of comments, I would > > need to create CommentCollection class, extend it from Collection, and > > override all the methods that are dealing with adding new elements to > > collection. Moreover, I can't have any hints from my IDE about type of > > collection's elements, so if I'll have code like this: > > >> foreach ($commentCollection as $comment) { > > >> $comment->getBody(); > > >> } > > >> There will be no way for IDE to know, of what type that object will > be. > > >> > > >> But there's how I could solve my problem with generics: > > >> class Collection implements Traversable > > >> { > > >> ... > > >> public function add(T $element){} > > >> } > > >> $collection = new Collection(); > > >> > > >> $collection->add(new Comment()); > > >> > > >> $collection->add("that will be error"); > > >> > > >> Actually, that's, again, all about type hinting. If we went so far > with > > scalar type hinting, then generics would also be a good addition. > > >> > > >> So, what you think? > > > > > > Personally I would hate to see this anywhere near PHP. > > > > > > -Rasmus > > > > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > Well, the example just shows what I've already got used to when working > with Java. > I like it and it would be of great help to me (especially in reducing the > amount of code to be tested), but there's a lot more around that, like > multiple generic types (new Map()) and how reflection would > deal with it... > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > --90e6ba5bc23315687804cc8ffa46--