Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92552 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61234 invoked from network); 20 Apr 2016 15:26:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 15:26:50 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.45 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.45 mail-wm0-f45.google.com Received: from [74.125.82.45] ([74.125.82.45:38760] helo=mail-wm0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/2E-14036-ABF97175 for ; Wed, 20 Apr 2016 11:26:50 -0400 Received: by mail-wm0-f45.google.com with SMTP id u206so87638603wme.1 for ; Wed, 20 Apr 2016 08:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=ESIn+BKacWmU/JEzF/AbwsiJAY3nEa2J1XQ3nWu4Teo=; b=pfCLu3rJtyRDoCSDpxr0XvCNjFfq+tDx1CNk0ufSd7oDg2/uRULiuDHT4A6apuCSGA NffyzBKkToNcW8igIchaAi6ULhl1aYWGQkuRwYMvo01p5m3ARJk5RPpG9xb6rIqRi+3x htyH0m+5MwHNXRPOcy5QJY+SBVjpn2w1sJtQ3lRZR292fePcSx9vHa/DVpH2CJDhewhN CtQ8rTA2pYszj+S/pjA/YomOfEq0hifKFUb+w6IHtwJ/H0vytRxJl9ZNtI33S7+Di35e e/uQ5SCrJYkBWeh+TZaYP8A6O5fEzqHSpHoLdi6v7+RBaMt7JqR+jygcnyYxKaL7EZkL DA4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=ESIn+BKacWmU/JEzF/AbwsiJAY3nEa2J1XQ3nWu4Teo=; b=Q4KXIyn8K9tHX5Lqo1SniOeMHiy+gZr47zgIJbySVUNY9ozvnUnLWCuDpRwqV1nUnp PAU3/twTg/z2wu4kDuPAbMado2IAQP90hCqb98GQaEoGQa6UsquYRLhztiFPD3dZ94no 6NApkucPUvJNUMPzbd5lAcdncCAWrmQEUUyGRGgmwFDEtMxQsx2fiCUY2K0IIljGRJ3b BUqP2UWsfa1XmfpVUQo+wWobTT+zeMVhjj66z3uLaH+3MoTOzFAGYPgx4z9ZF4CpQPnt Dy+mQpyV4Pal2WOxbitebZzDp1UzJi8ZHMGpqLHMd7NqsFclAwh4tWQjBbQePfGSJWpj PaVA== X-Gm-Message-State: AOPr4FXPO0ixz04YptMhCHtrprjhClZY00i9nn1YdsYUHz6IeLuzJyb9Z+Q9eqgRtFa+tA== X-Received: by 10.194.61.134 with SMTP id p6mr8942016wjr.67.1461166007233; Wed, 20 Apr 2016 08:26:47 -0700 (PDT) Received: from [192.168.0.77] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id e12sm10191878wma.15.2016.04.20.08.26.46 for (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Apr 2016 08:26:46 -0700 (PDT) To: internals@lists.php.net References: <3cc8a4c7-2640-11ae-a67b-06f909ac1e27@texthtml.net> <5716BB89.8030005@gmail.com> <571799B8.1060201@gmail.com> <57179C5F.9090101@garfieldtech.com> Message-ID: <57179F54.7020302@gmail.com> Date: Wed, 20 Apr 2016 16:25:08 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <57179C5F.9090101@garfieldtech.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC:generics] From: rowan.collins@gmail.com (Rowan Collins) Larry Garfield wrote on 20/04/2016 16:12: > On 4/20/16 10:01 AM, Rowan Collins wrote: >> guilhermeblanco@gmail.com wrote on 20/04/2016 03:54: >>> 1- Even though mentioned, I'd still use "extends" or "implements" >>> instead >>> of "is" (which would be a new pseudo-reserved keyword) to enforce >>> data type >>> consistency and prevent developers to potentially referring to one >>> thing >>> while consider another. >> >> Perhaps "instanceof" would make more sense here? "class >> FileProcessor" seems to exclude instantiating >> FileProcessor, because "FileHandle extends FileHandle" >> doesn't make any sense. >> >> You could read "class Box" as an assertion that >> the class passes the constraint, as in "public function __construct(T >> $t) { assert($t instanceof Boxable); }" >> >> Regards, > > I'm not an expert in generics by any means, but how is that different > than just > > public function __construct(Boxable $t) {} > > I thought the point of generics was for cases like "these two > variables must be the same type, but they can be any same type." > The is/extends/instanceof clause adds to the rule: "...they can be any same type, *as long as that type meets this constraint*" So using an unbounded generic, you could manually check: class FileProcessor { public function __construct(T $t) { assert($t instanceof FileHandle); } } $f = new FileProcessor($zip->getEntryHandle(1)); // "T" is substituted for "ZipArchiveEntryHandle" $f = new FileProcessor(42); // assertion fails! A bounded generic, using "is" as the keyword as in the current RFC, performs the assertion for you: class FileProcessor { public function __construct(T $t) { // no need for an assertion } } $f = new FileProcessor(42); // throws a TypeError My suggestion was that the constraint is like an "instanceof" assertion, so we could use that keyword: class FileProcessor { public function __construct(T $t) { // no need for an assertion } } $f = new FileProcessor(42); // throws a TypeError I hope that makes sense. Regards, -- Rowan Collins [IMSoP]