Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63579 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40778 invoked from network); 21 Oct 2012 11:34:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Oct 2012 11:34:04 -0000 Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-la0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:57872] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/9E-22055-9ADD3805 for ; Sun, 21 Oct 2012 07:34:01 -0400 Received: by mail-la0-f42.google.com with SMTP id e6so1149628lah.29 for ; Sun, 21 Oct 2012 04:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:cc:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=S6p4zD37QU7A5BhnzxLYoHNNyztBYAyB7QPJxurFbqg=; b=kptBtPf+cyDG0b+Q2G1uHNzoPPQwVEBP73uP86+/W82mQcDy/9QjKZxNi7XbWVcchD pgoRqHfvqS/b097TWwKz0M/+zEKB8iAo6gcE1KAmrZie1GyQc8Qyj/+70MmjgHA31ml5 pgM8KIuAUlyL87Zb9DvHTN07oO2/llukuCA+Z7plOLkvTRaXzjT8NTCbJIApz6oU+M9Z 8em9pIVLY680D786IYDSb5erDVPRkEuA6QsOWQ10Qagdi0iUhNuzYTxsveyzd6ALnHU+ 4hMOlcZmn6OMQwoavp/iUlE8aXFR0bCxKg7pvrG8SsftA/YWasU1mcuEdXqjtVqriR/k hQrg== Received: by 10.152.124.201 with SMTP id mk9mr5569293lab.33.1350819237906; Sun, 21 Oct 2012 04:33:57 -0700 (PDT) Received: from nikita-desktop (128-72-176-60.broadband.corbina.ru. [128.72.176.60]) by mx.google.com with ESMTPS id xw14sm2037428lab.15.2012.10.21.04.33.57 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 21 Oct 2012 04:33:57 -0700 (PDT) Content-Type: text/plain; charset=koi8-r; format=flowed; delsp=yes To: "Paul Dragoonis" Cc: "internals@lists.php.net" References: <712F4499-949C-4C6F-A142-736A1B156189@gmail.com> <50831148.1070808@lerdorf.com> <6E76ACFF-FD5B-4BB9-8180-990D0156ECD6@gmail.com> Date: Sun, 21 Oct 2012 15:33:56 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.02 (Linux) Subject: Re: [PHP-DEV] Generics proposal From: inefedor@gmail.com ("Nikita Nefedov") No, this is useful in any OOP-language where there is such thing as type, and people need to validate types. I unerstand what you are saying about PHP being an easy language, but in opinion if you don't want to use that feature you can not use it, as you can not use typehinting in functions for example. > 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/