Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108192 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96294 invoked from network); 18 Jan 2020 11:58:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jan 2020 11:58:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6ECB51804AC for ; Sat, 18 Jan 2020 02:06:08 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 18 Jan 2020 02:06:07 -0800 (PST) Received: by mail-lj1-f180.google.com with SMTP id u1so29004182ljk.7 for ; Sat, 18 Jan 2020 02:06:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NCHjWgOi4CSv0tvCDlyiJd7qvFXE+TycGx0ALMZda4o=; b=Yn3UsV1sb0+tDuzrl2diPl0Xd0tpkuLVeHyYf97PW9Fl/+rjuQrPZDmbSaW5USf1EJ Ktutdf6Cdvx3WOOrlTeZQCJ+W/3lBhrFbitgN+6EgIUY3A0/qYsW+kktEnvRVszDGaKQ w+LMF2qPePhuVnPiEUaCNVRdc+kzSeul1O3zWTNfNMUJ0wcZB7CxcZAaF1xAWayvKnO6 WNsR/4D7VhxeJu5ATZBUOyIwX12uTohHeA49qDUiq4jJLwSlOBx6pnHGdtgmPYIEzxS8 w5tBUFPP/GrEOI+2Ab8fQQlc0n3TdgKv/g0KsS93ZKMWhgQKsOqE63O/ofJv1OBHjY8Y HHWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NCHjWgOi4CSv0tvCDlyiJd7qvFXE+TycGx0ALMZda4o=; b=eSlGuEl6hVvMCzIYCiTbmy2FxaKkzozjpieT+yK9H0GtlPR96scGNgsN1MzsKqY/IF BHuYi3LT0I8VE5v4N9rJvq7CVN8txwkMdpDw5YAYQEMvJqHANoi5otWithKSlpBXUFBI zw24JxIe2ixNtOvMi26UkOYvArbUed1aAy5O7ulWex5ai3xfkv6lZ9lubszr2NVc6Vvz QlSZk4TgnJ8jG9ljUKwKkcB+6zgJzjHi/rJcHcXrJgWwTkQsRA7UafeYHhwomEvocoU/ 1ii3xMeR85fCR0o1SSawK1wrg9RuVO37fvKTlQQo3E+ITVc3NDZ0X52hmQi64sMMSPMJ u3Fg== X-Gm-Message-State: APjAAAUscl7RD1wJ9/rtSHM4JWke2hARz8OiqGkqcMYGKqriK+BjHkch VsoTqQqxomCh8ynC5ON6cB7JUCdl12TGgdsVPgc= X-Google-Smtp-Source: APXvYqz1u3UDmSF/rQKYVzsjXymJhZTT4tjIAL8xwE3szAVvKVg8cDOGKffbiTkrYs5H2CZ0a4c0+p4TjR1FW5LMpDE= X-Received: by 2002:a2e:8946:: with SMTP id b6mr8037629ljk.1.1579341964676; Sat, 18 Jan 2020 02:06:04 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 18 Jan 2020 11:05:48 +0100 Message-ID: To: Aran Reeks Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000c898f2059c673420" Subject: Re: [PHP-DEV] Typed array properties V2 From: nikita.ppv@gmail.com (Nikita Popov) --000000000000c898f2059c673420 Content-Type: text/plain; charset="UTF-8" On Fri, Jan 17, 2020 at 8:51 AM Aran Reeks wrote: > Hi Internals, > > I'd like to kick off a conversation to capture everyone else's thoughts on > tweaking / improving typed properties for arrays (for a PHP 8.x release). > > With all the work done lately to greatly improve the type support in PHP > (which is amazing by the way), I'm finding for the most part, I'm no longer > needing to Docblock as much of my code which is lovely. > > That said, there's a common use case that keeps me going back to them which > I think would be a good thing for PHP to try and solve as a language > feature - better typing of arrays to type their properties. > > IDEs like PHPStorm handle this structure already hence sticking to that as > a starting point... > > @returns []int > > This would designate the return of an array where all its keys are that of > the int type, but it works for any type. > > With that in mind, it might also make sense to allow a shorthand array > alias for array types anyway - array -> []. > > To use actual PHP examples, this would mean the following would be > supported: > > // Typed array properties ...values would follow any existing PHO type > function returnsIntArray(): []int; > function returnsClassArray(): []Class; > > // The same outcome > function returnsArray(): array; > function returnsArray(): []; > > I welcome all your thoughts on this proposal. > > Many thanks, > Aran > Hi Aran, Did you read through the previous discussions on this topic? https://externals.io/message/100946 in particular comes to mind. The primary concern about the previous typed array proposal was the O(n) cost of type checks, which required iterating over the whole array and checking the type of individual elements. Any new proposal in this area *must* address this concern. As far as I know, the only viable way to do that is to make the array intrinsically typed, which means that types are validated when elements are inserted into the array, not when it is passed across a function boundary. In other words, array generics. Regards, Nikita --000000000000c898f2059c673420--