Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87125 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80548 invoked from network); 12 Jul 2015 23:08:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jul 2015 23:08:21 -0000 Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wg0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:33922] helo=mail-wg0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/61-17022-F53F2A55 for ; Sun, 12 Jul 2015 19:08:18 -0400 Received: by wgkl9 with SMTP id l9so13195030wgk.1 for ; Sun, 12 Jul 2015 16:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=OaDGaES46tahNjmt8Qqss4qPhrlnuY/bFRAIz7l8DsQ=; b=ckxEoLEz1QRVC1RMS0g4aMMsoh7PoT1b8vxaa0qaPoOeGVK/xZ5po3HO9MRc7ciGgy Eutq4oDx+5RwVM0TKhaOqZppqXK2AOQGxe+uP3NFBiMzNHcs1Y735AoZKUm1oSd3c2MJ l2FDJrWjWjILObrVVHLKbRfmfRS/0lEEfpKEcF05RzDYBj0Vd80F021PtukZdpNcVPSP F27Unak2btGqB13c7y4H9tK5XY6CTsTA9fJDEFhrPDjjkOMIOiyv1g+g4kXww4qRFLWk 7qVwV6vZPvUvC0hDSbN6yGdh2yv97kYNxOEVAmzgJ1GCUk+5rCfqFVVrhMcnQv4K/3i/ IMXw== MIME-Version: 1.0 X-Received: by 10.194.58.167 with SMTP id s7mr61896722wjq.38.1436742490196; Sun, 12 Jul 2015 16:08:10 -0700 (PDT) Received: by 10.28.188.70 with HTTP; Sun, 12 Jul 2015 16:08:10 -0700 (PDT) In-Reply-To: References: <55A16375.4000707@php.net> <55A220D8.3090004@gmail.com> <55A2C1F2.8000301@garfieldtech.com> Date: Sun, 12 Jul 2015 17:08:10 -0600 Message-ID: To: Alan Willms Cc: Larry Garfield , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7bacc896c310c6051ab5adc0 Subject: Re: [PHP-DEV] PHP7 and types From: derokorian@gmail.com (Ryan Pallas) --047d7bacc896c310c6051ab5adc0 Content-Type: text/plain; charset=UTF-8 On Sun, Jul 12, 2015 at 4:51 PM, Alan Willms wrote: > What about arrays? How do I declare Foo[] ? > > http://ocramius.github.io/extremely-defensive-php/#/69 > > 2015-07-12 16:37 GMT-03:00 Larry Garfield : > > > On 07/12/2015 11:16 AM, Marcio Almada wrote: > > > >> Stas, > >> > >> 2015-07-12 5:10 GMT-03:00 Stanislav Malyshev : > >> > >>> Hi! > >>> > >>> Not completely bogus. At least with typed properties you won't need to > >>>> actually write the docblocks to have the IDE "hints". It's a minor win > >>>> for IDE users too. > >>>> > >>> I don't see "not needing to write docblocks" as a win, quite the > >>> contrary. > >>> > >> Of course it's a win. Or do you like to write docblocks for every > >> single class property or method (even when the member is obvious) just > >> to have a "@var" so your IDE can work? > >> > >> Not to mention you won't get any runtime/compile time check or > >> optimization from docblock tags, that's the main point of having typed > >> properties. > >> > >> In fact, in a number of projects I worked with, code without > >>> proper documentation (including docblocks) simply wasn't accepted into > >>> the repository. > >>> > >>> If you are using the term "proper documentation" to justify docblocks > >> everywhere even if they contain just a "/** @var string */", it's a > >> sign we've been using comments against us all this time (even if we > >> called it "doc comments"). > >> > >> But thankfully we are moving PHP to another direction. Do you remember > >> the "return types" voting results? > >> https://wiki.php.net/rfc/return_types#vote. That's because "function() > >> : type" is self documented and much more maintainable than than a > >> possibly sloppy "/** @return type */" on top of every method on a > >> codebase. > >> > >> While I don't think this needs to be mandatory, I also don't see major > >>> difference - so you have to write type instead of docblock, you still > >>> have to write something. > >>> > >>> But with the benefits already cited above. Docblocks should not be a > >> place for type information anymore, this was a workaround and we've > >> been slowly replacing it with a better solution (opt in types). > >> Property types seems to be the next logical step after adding return > >> types and scalar types. > >> > > > > I don't know why we're even talking about IDEs here. IDE auto-completion > > isn't the point, anymore than it was the point for scalar type hints or > > return type hints. It's about the language doing type checking for you > and > > static analysis, so that the language can find bugs for you. Eg: > > > > class Foo { > > public Bar $bar; > > } > > > > $f = new Foo(); > > $f->bar = new Baz(); // This line is clearly wrong and the compiler can > > check it for you. > > > > That's what the benefit would be. Easier IDE auto-completion is a nice > > extra, but not the main goal. > > > > +1 from me in 7.1. > > > > --Larry Garfield > > > > > > Since there is not typed arrays in PHP I would say you declare it as an array. Though in this case I would suggest a collection class that implements iterator and countable and type hint for this collection and make its job be to be a container of a specific type. class WagonCollection implements Iterator, Countable { private array $wagons = []; private int $index = 0; public function addWagon(Wagon $w) { $this->wagons[] = $w; } // implementations for Iterator and Countable } However, I could see an argument being made for typed arrays, but that is not the point of my suggested RFC and a separate RFC would need to be created for that. PS. Please bottom post instead of top posting. mailing list rules > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > --047d7bacc896c310c6051ab5adc0--