Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63574 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90243 invoked from network); 20 Oct 2012 21:02:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Oct 2012 21:02:07 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.212.42 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:62535] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/C7-22055-D4113805 for ; Sat, 20 Oct 2012 17:02:07 -0400 Received: by mail-vb0-f42.google.com with SMTP id fs19so1825502vbb.29 for ; Sat, 20 Oct 2012 14:02:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=/pfc8iyuax3jtoOQCB3EbLoG9xuSoRde6E/rj+X3L4c=; b=JbbpXF5xJpNEGopUCk84MwPd9R5lY7ot9AKPEfwAV27XucB1bxl19kFFrZbIOnAVVi 6RRtSd0CwCJTQ/NtYg8EoXI/o1z8b5yd3JpVkeem+cAzVZsip5QvFoJ3ejDtHANif/do ySPGRadkwF9UPz0UwG8F2ugT6PMqph8AbBg7vYaYIynp4bxkddUEVtypddilHrLRX6Hr gONvlwlYoX2kkTmw788LEW8bNqTKLa3ggP/nkD7kFyar7put52LdqQz3isioUnzMYEvz QD+2vAUYbquMOtL5Qoo6vzIC36NNEqDkRPDZTplic0VFbHYprJHJnPiYIc0KswBiKtVJ ONVw== Received: by 10.52.65.147 with SMTP id x19mr5857972vds.113.1350766923007; Sat, 20 Oct 2012 14:02:03 -0700 (PDT) Received: from [192.168.200.148] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by mx.google.com with ESMTPS id dp6sm5022054vec.11.2012.10.20.14.02.01 (version=SSLv3 cipher=OTHER); Sat, 20 Oct 2012 14:02:02 -0700 (PDT) Message-ID: <50831148.1070808@lerdorf.com> Date: Sat, 20 Oct 2012 14:02:00 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: Nikita CC: "internals@lists.php.net" References: <712F4499-949C-4C6F-A142-736A1B156189@gmail.com> In-Reply-To: <712F4499-949C-4C6F-A142-736A1B156189@gmail.com> X-Enigmail-Version: 1.4.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQl/a+zheAFUpMZ6RV71GK4ecP33caPSvDQKbM8SuF1STBsnPvHl2LETJswpOsB1I2exwf3n Subject: Re: [PHP-DEV] Generics proposal From: rasmus@lerdorf.com (Rasmus Lerdorf) 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