Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71235 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88379 invoked from network); 18 Jan 2014 04:50:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2014 04:50:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.54 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.215.54 mail-la0-f54.google.com Received: from [209.85.215.54] ([209.85.215.54:63087] helo=mail-la0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/02-10526-0180AD25 for ; Fri, 17 Jan 2014 23:50:25 -0500 Received: by mail-la0-f54.google.com with SMTP id y1so4159675lam.41 for ; Fri, 17 Jan 2014 20:50:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=aVWr7RIyFnYXAhnrezVSa4M1euKscbe2rURmAphmlfM=; b=uQCD5mBR2u+WNA3APllFqRTnrHXD3RPwMm5tEn5IvCqkLuu4X6hTNqT6TJZFAR2ij2 t3xR5Mc622IRdQmYMBoAsQwzj45CFyR+mBRzGqC4tB2TuXzDNSXKXjFNa1PFtSR/d42A wYkundYwDP6m4cCB4gro9nsWidneVgjjM6Qvsrw1SNaF7xCO+8To0A9GWNWuXm031dUu C7ZAQq8vFWLXtMWILeUL4Fm6YhwpispsRZ4kkeFjpJSfF1g3dPHr0AvnkYVOfPEsAw4S tlJUKXfnDE0NaF3Px1w9Ifds2Gz88GksuMs9FODA/aFltwndJ+Tqakc/o1ublKd606a3 rv1g== X-Received: by 10.112.144.69 with SMTP id sk5mr23273lbb.44.1390020621620; Fri, 17 Jan 2014 20:50:21 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.6.68 with HTTP; Fri, 17 Jan 2014 20:49:41 -0800 (PST) In-Reply-To: References: Date: Sat, 18 Jan 2014 13:49:41 +0900 X-Google-Sender-Auth: XfOSB1U3M7H0iR6AiNFOaaylFkA Message-ID: To: Sara Golemon Cc: Philip Sturgeon , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b3432f461da7f04f037651b Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: yohgaki@ohgaki.net (Yasuo Ohgaki) --047d7b3432f461da7f04f037651b Content-Type: text/plain; charset=UTF-8 Hi all, On Thu, Jan 16, 2014 at 10:06 PM, Sara Golemon wrote: > > https://wiki.php.net/rfc/arrayof > > > I'm going to fowl up this conversation by describing what HHVM's Hack > syntax does for this. Partly to encourage PHP to do the same, partly > to just lay out the edge cases we thought about on the way to > developing the syntax we landed with. > > * Generics Syntax - Allows creation of typed classes which repeat > common functionality with specific implementations > class Foo { > protected T $foo; > > public function getFoo(): T { > return $this->foo; > } > > pubilc function setFoo(T $foo) { > $this->foo = $foo; > } > } > > $f = new Foo(); > $f->setFoo(new Bar()); > $b = $f->getFoo(); > > * Typed arrays - Arrays are a special primitive which can be typed as > implicitly or explicitly numerically indexed, or associative, and to > specific types: > array or array > > function foo(array $numIdxArrayOfBar, array > $numIdxArrayOfBaz, array $assocArrayOfBong) { ... } > > Since the value type is unconstrained, it can be a generic type as > well, so a numerically indexed array of associative arrays of strings > would look like array> and so on. > > * Nullable types - Any type preceeded by a question mark may be that > type or null: > function foo(?Bar $barOrNull, Baz $bar, ?Blong $blongOrNull) {...} > > * Soft types - Any type preceeded by an at sign is hinted as that > type, but not checked: > function foo(@Bar $IHopeYoureABarObject) {...} > > ---------------------------------------------- > > Within the scope of this RFC, I want to encourage > array/array syntax (with nullable/soft modifiers) as I > think they cover every edge case presented by this discussion so far. > It also covers elements not handled by the proposed syntax (index > types). The syntax will be familiar to developers coming from C++ and > it leaves room to entertain generics in general. > I prefer generics syntax. It's rather common syntax and has more abilities. It's better to have common syntax with HHVM, too. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --047d7b3432f461da7f04f037651b--