Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63573 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88833 invoked from network); 20 Oct 2012 20:58:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Oct 2012 20:58:44 -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:48499] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C4/77-22055-38013805 for ; Sat, 20 Oct 2012 16:58:43 -0400 Received: by mail-la0-f42.google.com with SMTP id e6so984071lah.29 for ; Sat, 20 Oct 2012 13:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:from:content-type:x-mailer:message-id:date:to :content-transfer-encoding:mime-version; bh=dpQJsslxhlMux6tsmzwW3nKoCIYP/S9QViNB6wPpVBU=; b=MiqR68xxZ8CGLY9uLbEEbZHAzKuBWPt0YQiCrPITfDP0LEogwhQM43dVasdYVI8vxX iRpZjd4CLARI7WP5k418faWaVx2vI4x2ybmOkO1Utv6SAGj3IFUgzvmC9ct2ag56Z32P uyb8FbOVnz0sqRyid9kL1hDYr8AzM58DZYUF/UDByUK2GaDTxsRiuECu9n27PPyYrdzg zcyamYVWVsBzGyuE5b5Mik/w0MvQNq7xLwMS1+SuSEKcNxgV/fEWUYbODDgKe+/sslTA IkJHByUrlxWac+sO6ahTykEfJ7+6hy2Dy/855iFI2rVpWJ16haR1yl1pM7GQWl6mDHZa 0OQA== Received: by 10.112.23.197 with SMTP id o5mr2021286lbf.114.1350766717313; Sat, 20 Oct 2012 13:58:37 -0700 (PDT) Received: from [192.168.1.2] (128-72-176-60.broadband.corbina.ru. [128.72.176.60]) by mx.google.com with ESMTPS id gt17sm1616200lab.6.2012.10.20.13.58.34 (version=SSLv3 cipher=OTHER); Sat, 20 Oct 2012 13:58:36 -0700 (PDT) Content-Type: text/plain; charset=us-ascii X-Mailer: iPod Mail (10A403) Message-ID: <712F4499-949C-4C6F-A142-736A1B156189@gmail.com> Date: Sun, 21 Oct 2012 00:59:01 +0400 To: "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (1.0) Subject: Generics proposal From: inefedor@gmail.com (Nikita) Hello, list. I want to propose generics. For those, who don't know what it i= s, here's example: say we have a Comment class, that has a method getBody. A= lso 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 me= thods that are dealing with adding new elements to collection. Moreover, I c= an'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 =3D 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 scal= ar type hinting, then generics would also be a good addition. So, what you think?=