Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63575 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91734 invoked from network); 20 Oct 2012 21:10:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Oct 2012 21:10:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=mikegstowe@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mikegstowe@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: mikegstowe@gmail.com X-Host-Fingerprint: 209.85.223.170 mail-ie0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:33161] helo=mail-ie0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/18-22055-72313805 for ; Sat, 20 Oct 2012 17:09:59 -0400 Received: by mail-ie0-f170.google.com with SMTP id c12so2558821ieb.29 for ; Sat, 20 Oct 2012 14:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:x-mailer:from:subject:date :to; bh=8V7/O4gZ7koyrc8zWWEHmujw8zkEK6MnPIDDVO/QQF4=; b=GS5ICmXkJLAveGrsMigNhxQ3AMtz6LTX1Ltcwv4REtWk62eOaful8D11IQr1VAx1ku IT/PfSHMYLV8UtGPWSNHDtaeL2wLHQkzQuQSfZtxBmTWJREKmf4X8Mfv68rYpS4ht+sS wPIdj+srDuo8uNqMfLKNK7c3oHlRqD35qIbXK6rvL2/RbZLjM6hjRvCWEtvHFrQ7oYZc HxGUwc0Zrvl5iXByEN2sEwrzq/HtDupWzxhZp2gyPyalXJhCtEJaXK7AJh87zld5rrKg 9cVkXKcY8VVkPgWKHKjt4NB6GUV9C10Ya6JrBKHdDB5prqHOgF7Aj4zFHUWS43AYcX8i kkGw== Received: by 10.50.185.231 with SMTP id ff7mr5280864igc.40.1350767396720; Sat, 20 Oct 2012 14:09:56 -0700 (PDT) Received: from [10.193.92.56] ([166.137.81.77]) by mx.google.com with ESMTPS id o9sm18917247igd.7.2012.10.20.14.09.54 (version=SSLv3 cipher=OTHER); Sat, 20 Oct 2012 14:09:55 -0700 (PDT) References: <712F4499-949C-4C6F-A142-736A1B156189@gmail.com> <50831148.1070808@lerdorf.com> Mime-Version: 1.0 (1.0) In-Reply-To: <50831148.1070808@lerdorf.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-ID: <6E76ACFF-FD5B-4BB9-8180-990D0156ECD6@gmail.com> Cc: Nikita , "internals@lists.php.net" X-Mailer: iPhone Mail (10A403) Date: Sat, 20 Oct 2012 16:09:50 -0500 To: Rasmus Lerdorf Subject: Re: [PHP-DEV] Generics proposal From: mikegstowe@gmail.com (Michael Stowe) I see what you're trying to do but not a big fan of how it's being implement= ed in the example given.=20 - 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 i= t 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 cre= ate 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. >>=20 >> But there's how I could solve my problem with generics: >> class Collection implements Traversable >> { >> ... >> public function add(T $element){} >> } >> $collection =3D new Collection(); >>=20 >> $collection->add(new Comment()); >>=20 >> $collection->add("that will be error"); >>=20 >> Actually, that's, again, all about type hinting. If we went so far with s= calar type hinting, then generics would also be a good addition. >>=20 >> So, what you think? >=20 > Personally I would hate to see this anywhere near PHP. >=20 > -Rasmus >=20 >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20