Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118104 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87987 invoked from network); 27 Jun 2022 10:13:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Jun 2022 10:13:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 425ED1804F8 for ; Mon, 27 Jun 2022 05:04:06 -0700 (PDT) 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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 27 Jun 2022 05:04:05 -0700 (PDT) Received: by mail-yb1-f173.google.com with SMTP id x184so13589484ybg.12 for ; Mon, 27 Jun 2022 05:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b9xQhLsfnGXcisolRXce8QRFQleTkkj5Gqluc3R4JMU=; b=LoobjdwI8GJ1Js1O0K2nFAqzhbuo4z4kLpucClkJ67le/rIBnp1X4db42nlm5k6f68 KKZRGMyyHAl/XeWsSWKMvia+teoOOSI5qtcvVgUKlqe9oeVTujLk3r1gC8sETwVXjLTX bBxmPaK5s/bRPwvqFTRkicaej0mrjlqNlrihWxfwpWsH8rxhZhdeM5oahMU2Rod55xs2 e5+eoqpEwa1E5GuWj1dfeqs/xpZDd64zhWwQj6vp262rnTEl8iGUQYeUr0t7Wj6/YO8U 1nohCx3/dnDZhRQldP2a4oT9AwUUHSAtH7ZLBfwMDKYTBfxfg8mrTje/0Rhu9qesdDFq cIWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b9xQhLsfnGXcisolRXce8QRFQleTkkj5Gqluc3R4JMU=; b=05VBFGmc5Yjrb+MWccXgC1xGgVKCbjiyHBLhM3ucVDx6nLCUB3JdVA76bzC6dSOcyO ZzVmryIdRS5xoiS9IFBPnkw6rYf9ZqoR1E8/S+yw3DnGu02d6KA6ZCPkIY1Jecmx9Fqs diqFH+bsbQb5aWO9WrFYLWnbOvOK7QK8oNHadnUJbgff8iBNxswvzOlVg+qOsnQYQvvZ cGlK2nxEetB2EcelvqWuefVouBvJNUTlqvqq2l4tFAbtXZ5dbUFzcFIWHMgwjgYEum7y jHZ7aTodIeWrT2ZxiGkRzhqI5SQZpQas15P4ODiVA7XD44ormW8qcEJxEq2RCXKm3T8D /Dng== X-Gm-Message-State: AJIora9IfvHiCTJWV17hqEl9Ussvw+tCgaNmP0ZmYj5AGL50ECBzYoTc 98DVTNa4iM4DpYIqdwr86drBbBSLAidoPsRzp9aNQx/RRw== X-Google-Smtp-Source: AGRyM1vw5akfaxEc99Pj6bDqyvgx6UnbLQ9n5awprDPpp/tQG7eCx8+ul7QelI5y3PqLcig1efwdXZ7e7fRQKRQrItY= X-Received: by 2002:a25:d30b:0:b0:66d:7a2:d4b5 with SMTP id e11-20020a25d30b000000b0066d07a2d4b5mr886169ybf.9.1656331445059; Mon, 27 Jun 2022 05:04:05 -0700 (PDT) MIME-Version: 1.0 References: <9C11261B-B9D0-4342-81EB-60276B3036E5@php.net> In-Reply-To: Date: Mon, 27 Jun 2022 14:03:54 +0200 Message-ID: To: Nicolas Grekas Cc: Rowan Collins , PHP Internals List Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Auto-implement Stringable for string backed enums From: guilliam.xavier@gmail.com (Guilliam Xavier) >> Symfony YAML has a `!php/const X` feature, which also works when X is >> an Enum::CASE; how about a `!php/enum_value` feature? > > I submitted something similar today at https://github.com/symfony/symfony/pull/46771 And I see that it has been merged ;) >> Otherwise, I also like Rowan's suggestion of implementing "internal >> cast handlers", so that non-strict users could call e.g. > > I had a look at gmp for example: cast handlers don't work when calling a function. > They do work when explicit casting and when doing loose comparisons, but they don't when calling functions Well it works for `string` at least (even though `GMP` does *not* implement `__toString`), e.g. https://3v4l.org/cRnnW The TypeError for `int` may be related to the fact that e.g. `+$gmp` (or `0 + $gmp`) gives back a GMP (not an int like `(int)$gmp`)? (But indeed I don't know much about that... nor if it could be made opt-in) > Rowan's proposals about sets could solve this in a very nice way Reminded me of e.g. https://stackoverflow.com/questions/6422380/does-any-programming-language-support-defining-constraints-on-primitive-data-types (mainly integer ranges, but the concept of "domains" looks similar) Regards, -- Guilliam Xavier