Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124567 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id BB97B1A00B7 for ; Wed, 24 Jul 2024 09:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721814575; bh=GYrmsVACuHXNmQ7Bw/618gmLgfI/4rVKzdc7dzoFFZk=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=QKJGlcjj8nSwWdIZ6CFkFwXlfHbwORqe6ATgWwQ33djP+kPTUYIqOmfaGErhUpk5z +DHX2EYP4OH1m3bJpb7ocPcJF91DteWFELI/xDEWzXdKdZ/lWehgVfZxScG38sWSBs CDU+F9KJaKPU+cUeHbvkPc9rPbHc3C4WGX7F0phciKOJnO4o0oeU3K8axKQP6EdOLa 67RX5pYhxSqIx7h5eAvwbR2pPrhZnLxNFtZ9DscQFsKiSWKBzvMxPu3fB0ehvXBsHV Pjx4zdZFhZKSMFv+PekQkBWhb8nGV2Z858+em5rxZZjqMH6t26+5D7HTICZET27eci v3regW5GXwV+Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C934C18005B for ; Wed, 24 Jul 2024 09:49:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 24 Jul 2024 09:49:34 +0000 (UTC) Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-65f9e25fffaso68675977b3.3 for ; Wed, 24 Jul 2024 02:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1721814479; x=1722419279; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JIGEMDRXW72T0sqes2e/79MUqozxoR7o0+c/clL4bqY=; b=F5jqc6DU+lCLz9um9ld3OgMgPOXvcBX2WoJqNMvDPHtfm0t8+MkklEne27oFUOxY4O VlcY7IhhT3+cXlp2BaXcpnrRrh8SLN1quWqUUFJ/xlQs2XaO5VlG3FbdrhoHVsOYROE/ c8XpfChM6bao610azAN1cFq8ZhX4bjrK4XeW5Qyy1QjtRejQH/0F2oBdkpcEPj/WfnXh FaQ6HCUEHnVxgVYFYxTUXt+YOl2nLVQv5GQ4ta2zBrYJWZHdBX6hCKm6PGfbYIQxH6JE b0mu0bZbfRXHqNJZv+01FpjDvrjSgjpGCP4GeLhlyo2IE0TUkknAry4CH06jgfyAsCup RXTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721814479; x=1722419279; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JIGEMDRXW72T0sqes2e/79MUqozxoR7o0+c/clL4bqY=; b=HUzZaBDOUt9GgS3ZR/YVO7CeqHPmO7q7sntBDZigBLSuVQJsHDo7zEA1GwagjPQVzu b78plkgsBvr3dzXv3FyrZ5wZoFbpFS9ci2EqgyJv3vMBwhqg4I3WBgmm7huUoKi70xCH nhrVYT4Mf3GxDhi2uOjxRmo+jTgqXsswIH5UyFfj5yrQQ53MKG97bF4ogiVDawbU7Cqg SWVI/aV2aw4Gv7JLNSy82iPSbkX7hRKp8xOBmb2GJ9/qhrO92M43+iQTPVpGz7p/J2Bq l0eZbmmX0w2+SUpONsfcYqOoBaQZzybm43itYvRvLT15wOPc64+SPSgwG4jzdXxMIW2V S7lQ== X-Gm-Message-State: AOJu0YwGpFGFiaoEuhqveJzFQnIghQkWezXuKfQ2VMnoRhhGkqhU05Ep xxkxpZkju6PvNEiz34sOcdgBGBPyF2lvwJ5uhnBnNt6+SmKf0oTRuaSAIn1er4sSyQuutAhs79J TGSI= X-Google-Smtp-Source: AGHT+IGYZHKOdtJkLzSGx49FXQnH1n6XW6n+VdI8DY3rIMkeBf74w6bUDm+H6SIQ3756uISXrujxzw== X-Received: by 2002:a05:690c:398:b0:627:d23a:4505 with SMTP id 00721157ae682-6727962c1dfmr16658037b3.3.1721814479444; Wed, 24 Jul 2024 02:47:59 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 00721157ae682-66951e7de0esm23905437b3.6.2024.07.24.02.47.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2024 02:47:56 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] [RFC] [VOTE] Deprecations for PHP 8.4 In-Reply-To: Date: Wed, 24 Jul 2024 05:47:54 -0400 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Larry Garfield X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) > On Jul 23, 2024, at 12:26 PM, Larry Garfield = wrote: >=20 > Hypothetical pattern matching example: >=20 > $foo is ['a' =3D> int, 'b' =3D> $b, 'c' =3D> mixed]; >=20 > That would assert that there's 3 keys. "a" may be any integer (but = only an integer), "b" can be anything and will be captured to a = variable, and "c" must be defined but we don't care what it is. >=20 > The suggestion is to basically alias _ to "mixed" for pattern = purposes: >=20 > $foo is ['a' =3D> int, 'b' =3D> $b, 'c' =3D> _]; >=20 > As "there's a var here but I don't care what it is, ignore it" is a = common meaning of _ in other languages. But that would need to be = disambiguated from a pattern saying "c must be an instance of the class = _". Technically any symbol/set of symbols could be used there (as it's = just an alias to mixed, which has the exact same effect), but _ is a = common choice in other languages. I do not see this use-case as compelling. =20 `mixed` is perfectly sufficient and using `_` for a data types just = gives two ways to do the same. Not that multiple ways to do the same = thing is necessarily wrong, but I think it needs a better justification = than just to save characters. Besides, it has the potential to confuse = people as to its exact meaning whereas `mixed` does not. OTOH, if you really want to say characters =E2=80=94 albeit not as many = =E2=80=94 then choose `any`, which is certainly less likely to be = confusing and has an analog in Go, TypeScript, and Python, at least. Also, AFAIK, few (no?) other languages actually allow for using `_` for = types, they only allow using them for variables. I know that to be the = case for Go, and if I understand the docs correctly it is also true for = Rust, Zig, Haskell and Swift, with caveats for Rust. =20 - Rust allows underscore for type inference, e.g.: let x: _ =3D "Hello, = world!"; - Also for a Generics' type placeholder, e.g.: let vec: Vec<_> =3D = vec![1, 2, 3]; - But as for Rust pattern matching, the underscore is only used for = values, not types. For any other languages, I cannot say. > In theory, that could be expanded in the future to something like = (note: this hasn't been seriously discussed that I know of, I'm just = spitballing randomly): >=20 > [$a, $b, _] =3D explode(':', 'foo:bar:baz'); This is actually where a "blank" variable represented by `_` actually = makes a lot of sense. It is also how Go and Zig use them and = effectively also how Rust, Haskell, and Swift use them. =20 Unlike for types where we have `mixed`, there is no current globally = consistent alternate to using a blank variable in PHP. The only option = is to use an arbitrary name that other developers won't know the = intention of unless the developer adds comments to the effect. In summary, although I don't have strong feelings about deprecating = classes named `_`, I do not think the arguments made for disallowing = them actually have any analog in any other languages so I question if = there is valid justification for the deprecation. #jmtcw #fwiw -Mike=