Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124974 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 15AD91A00B7 for ; Fri, 16 Aug 2024 11:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1723808234; bh=Ndc9OjmxDni25fo1pFEU6OCtKkohozw+XGi6K7tFcpw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=YNF1eMcQtCXLZwz0w2C7wz70sUf9s+x5FEsTPRK05rmGyfPfTgqMcEFwm5rQdMI3k jhNDRvpk/x3mIdrJtCcnUWKxKYq0A5j6Bvn3P4J5+Z3OJEDOQO9C2cuII7iObsi7Xw f5V99NILABqaI9atbTWpfiYXf35/AOMq6GIU5OWKV1YmPG/JubwyPs8YAPh0i1zyLW JRM3z/TgQ7YuSKUKBw2BCPpU2ofXBXeiWVewLIm5Ry0mm4GpzAUf8EvPiB7S0eeh/+ UjOc4w+4kpBU9GaAX1jFwNxp7LYJlYbjSXVPMeVBlJLs6EcrYozEdww4JqWJQBHCeI eXBAF7oIvyqUA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 307C8180062 for ; Fri, 16 Aug 2024 11:37:14 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 ; Fri, 16 Aug 2024 11:37:13 +0000 (UTC) Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e0bfa0b70ceso1858470276.2 for ; Fri, 16 Aug 2024 04:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723808126; x=1724412926; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Y7wD3FCITio7F8Lt9Po2rcHcY9ZFQwyCg7QT/H1yI6E=; b=nG5KbU2j7QKRH5jT4kUmqIisQC0IL904RzVidP4XCKNcvWWIY3lQ4rNocDl+m0ndGp jw8i1/8yzv43/1EEiDAEd/NN/i8zxBQhZNqBOJwALvWN9iI/E6rZjQY49AHmbP38V4x+ 5gBK/1y22TT5egVBul2AXgtvbUptFKsybxMbQ3bR2gvT0vGKXHPKCVd0lxc7mPhGBRWv NTcaXE2pmfd693icZXu6EDhyIMRw7939gKHAqSs8TeOZdqcHHlh5pFdVKxRlN/UuRu+r xzYqBxj29fUpxs1+g1eEoM82/z4x2ECC78Uh/hvxRiQa7kDvAMxnE+0a3ej6fcL12hYf bEGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723808126; x=1724412926; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Y7wD3FCITio7F8Lt9Po2rcHcY9ZFQwyCg7QT/H1yI6E=; b=UVcBMLzNZjf5M2gyuyyacQ0+8M4pZZz7juEPubhFKpMSrbV1VOoRTwKEDnmENNPVPu OjGvSMjW/6FZpZCY5Wa0qNXVxtg+ZMOYKkHuczGxdB1NYfjEsRzmFI4U+ic1l5phFOf/ xm1u7NjJbK8K9NH5xdMmyMAexPFvvQMAw9zcjg83XwVYry8MbMzgY346wFE7ydboYAps VywhE7b0dafA8b8JCEDxelM47cheJNPJw1IQoW2CYp4mGpF2qaIMPH6nxJ3cJowkVtwY zQKlowsKZl1yWhAVXyZNnnP9psc9GADQP/QN9SeqTHsBy1i6iG/28oqk5xTlBd0IAs72 z+FQ== X-Gm-Message-State: AOJu0YzS63ewcjRvNWy/LUHJFfXG+AQZjZ5eP/Oer0Yre2ZE14CkC0+b UUe3+CR+ETvBDDIiGolOPIpXL7gly09o49aaAtMZnbIFS+BPK0kBanPD7vLLwd++FcFocsWxU6Q AM5hXzKQKHdqLCGTTbhVKxhI2FBE= X-Google-Smtp-Source: AGHT+IGFkmIUK9VWX2q4ALWWJuRlR7lM8n55IaeFFlBK6JQEfIs7aOL36I2nisxEOiqME+xd4sxO3D4H2Pblos81XXU= X-Received: by 2002:a05:6902:706:b0:e0b:2683:d688 with SMTP id 3f1490d57ef6-e1180fd8337mr3765713276.40.1723808126096; Fri, 16 Aug 2024 04:35:26 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <34548342633f1d87b2fc77c643bd895a18f71b66.camel@ageofdream.com> In-Reply-To: <34548342633f1d87b2fc77c643bd895a18f71b66.camel@ageofdream.com> Date: Fri, 16 Aug 2024 14:35:09 +0300 Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] Class Constant Enums? To: Nick Lockheart Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000045e0e061fcb5b48" From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000045e0e061fcb5b48 Content-Type: text/plain; charset="UTF-8" Hi Nick, > > Is there any interest in having enums as class constants? > > I'm often finding cases where I would like to have an enum inside of a > class, but don't want a free-floating enum that's basically like > another class. > > ...... > > class SSHClient { > > public const enum CommandResult > { > case Success; > case Failure; > case Unknown; > case Timeout; > } > > // ... > } > > > // Usage: > > SSHClient::CommandResult::Success > I feel this topic could be maybe more broad and be called "nested classes" that are already supported in multiple languages: Java, Swift, Python, C#, C++, JavaScript, etc. The syntax you showed is usually identical with what other languages use, except that probably the const is unnecessary. The nested class can have visibility as sometimes having it private makes sense. Accessing it through `::` is probably fine, but a deeper look at the grammar might be necessary. The nested class would have access to parent class private properties and methods. I also mentioned this topic on the subject of defining a type in an autoloader compatible way. And indeed, a type could also be defined nested in a class if we want to support that as well. Now, this feature is not simple, and I think it needs proper sponsorship from someone experienced with internals. Regards, Alex --000000000000045e0e061fcb5b48 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Nick,

Is there any interest in having enums as class constants?

I'm often finding cases where I would like to have an enum inside of a<= br> class, but don't want a free-floating enum that's basically like another class.

=C2=A0
...<snip>...=C2=A0
=C2=A0

class SSHClient {

=C2=A0 =C2=A0public const enum CommandResult
=C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0case Success;
=C2=A0 =C2=A0 =C2=A0 =C2=A0case Failure;
=C2=A0 =C2=A0 =C2=A0 =C2=A0case Unknown;
=C2=A0 =C2=A0 =C2=A0 =C2=A0case Timeout;
=C2=A0 =C2=A0}

=C2=A0 =C2=A0// ...
}


// Usage:

SSHClient::CommandResult::Success


<= /div>
I feel this topic could be maybe more broad and be called "n= ested classes" that are already supported in multiple languages: Java,= Swift, Python, C#, C++, JavaScript, etc.

The synt= ax you showed is usually identical with what other languages=C2=A0use, exce= pt that probably the const is unnecessary.
The nested class can h= ave visibility=C2=A0as sometimes having it private makes sense.
A= ccessing it through `::` is probably fine, but a deeper look at the grammar= might be necessary.
The nested class would have access to parent= =C2=A0class private properties and methods.

I also= mentioned this topic on the subject of defining a type in an autoloader co= mpatible way.
And indeed, a type could also be defined nested in = a class if we want to support that as well.

Now, t= his feature is not simple, and I think it needs proper sponsorship from som= eone experienced with internals.

Regards,
Alex
=C2=A0
--000000000000045e0e061fcb5b48--