Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63576 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94925 invoked from network); 20 Oct 2012 22:11:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Oct 2012 22:11:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; 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: ocramius@gmail.com X-Host-Fingerprint: 209.85.223.170 mail-ie0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:63248] helo=mail-ie0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/78-22055-A8123805 for ; Sat, 20 Oct 2012 18:11:23 -0400 Received: by mail-ie0-f170.google.com with SMTP id c12so2594188ieb.29 for ; Sat, 20 Oct 2012 15:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=q/9atZgJsUBAyQjfIulEeXtP4Ja9g5CY3lbwB6gBcok=; b=x4+VZhY1ME+uKHbfjto2cG6PyCY2fcbBnxjg1paHADNyyihFN0ZmbcztmtwdfnkVGf cCFNMKkdnzWcUQRTutMBcGB1TUZVN0gsySfE4AeRUGuNYW7vTLwex9zVW0FYPXU7x57g WnqIkbscUFsdfpzkY2QCV4n0Tbk7Fc6Ta5O9HosvLGwpCn70oiiu81gX+tk6tOfToXXT +OAfWLjUUYvHib2oH/+qUCZ1Dm/OM3M788LC385lY9ewEHJcQtNcRwAQfTg9fGIgXQj0 D6GkS8qIkS16sR7XyT3UfFiV4tWK0lE9dhZTCD2bIfckME8+gmgJLlN/qO8LHgZvsch4 MC6Q== Received: by 10.50.53.170 with SMTP id c10mr5397098igp.45.1350771079081; Sat, 20 Oct 2012 15:11:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.136.81 with HTTP; Sat, 20 Oct 2012 15:10:58 -0700 (PDT) In-Reply-To: <6E76ACFF-FD5B-4BB9-8180-990D0156ECD6@gmail.com> References: <712F4499-949C-4C6F-A142-736A1B156189@gmail.com> <50831148.1070808@lerdorf.com> <6E76ACFF-FD5B-4BB9-8180-990D0156ECD6@gmail.com> Date: Sun, 21 Oct 2012 00:10:58 +0200 Message-ID: To: Michael Stowe Cc: Rasmus Lerdorf , Nikita , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d042f9d66576f1e04cc84e63f Subject: Re: [PHP-DEV] Generics proposal From: ocramius@gmail.com (Marco Pivetta) --f46d042f9d66576f1e04cc84e63f Content-Type: text/plain; charset=UTF-8 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/ --f46d042f9d66576f1e04cc84e63f--