Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71184 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19808 invoked from network); 16 Jan 2014 13:06:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jan 2014 13:06:42 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.220.50 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.220.50 mail-pa0-f50.google.com Received: from [209.85.220.50] ([209.85.220.50:61742] helo=mail-pa0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/85-24763-069D7D25 for ; Thu, 16 Jan 2014 08:06:41 -0500 Received: by mail-pa0-f50.google.com with SMTP id kp14so2627962pab.23 for ; Thu, 16 Jan 2014 05:06:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=lB3nm8oiM8LO33siu4S8HkSxgkbE1rvSDMJa/fvxACQ=; b=cjmZK7bM0KlLkm9opguQlmx/TApwrzMTBLm/YBcf87R6vNTrUIuPbSrsbKcNWox1tg olWtthr0W9RB5ieWq5ttwknIcG/L0AjhzzWYZArNMpCnKBV6vEYmDsgT5rd2YimMv2Zf x51x9U7Y7TtrWBE2zQlBsmM8CYGmEOoASm5VZwrymFXRe7Nw7gY2GJ3dyIEjeQ3JXYpz 8RE/N5RwsDEzBdIzWXj3NpiRyot5XwIVgzSVIG9LN+n5gaPFzs2orjKCF4nJ0NU+9wk1 68sy3iN2D/24yQU0ZDbNLkasg46tSqc/XdJcC9H5BCwjO02ODWadYF2Snwe+BwrfL6zs FwJg== X-Gm-Message-State: ALoCoQnTltM2wRYgmUriuG7XoC5aGNnT3w6ppR+gFnGghjlGNh0/WoeA4n7z+/gAibNk0TnwQaty MIME-Version: 1.0 X-Received: by 10.68.96.99 with SMTP id dr3mr9905246pbb.40.1389877598242; Thu, 16 Jan 2014 05:06:38 -0800 (PST) Sender: php@golemon.com Received: by 10.70.77.164 with HTTP; Thu, 16 Jan 2014 05:06:38 -0800 (PST) X-Originating-IP: [2001:470:1f09:2fa:22c9:d0ff:fe87:295b] In-Reply-To: References: Date: Thu, 16 Jan 2014 05:06:38 -0800 X-Google-Sender-Auth: DQJo86eHyLvaCRmAS9PCDu5-i-Y Message-ID: To: Philip Sturgeon Cc: "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: pollita@php.net (Sara Golemon) > 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. -Sara