Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112466 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46004 invoked from network); 8 Dec 2020 09:42:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Dec 2020 09:42:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 006CF180533 for ; Tue, 8 Dec 2020 01:11:13 -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=-0.2 required=5.0 tests=BAYES_20,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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 ; Tue, 8 Dec 2020 01:11:12 -0800 (PST) Received: by mail-wm1-f44.google.com with SMTP id q75so1677066wme.2 for ; Tue, 08 Dec 2020 01:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=SgyXWIvRtBQKlUq9mBeiJwHxh+LLhPqX7J4QDpZqGM4=; b=s/FNbh1EbGPRJR3/107OgdWzFNLfQf1C34nwSrhOLFTEw1HLxmPr17/Afii3hp3WIF IBrbfao14zkISjs4w80zchdmIgqs//mopaS8WhyHJ3R/3SxhrtG7+LHINvhobhMNfzDe SsPPhxNTLmbEunjkTCAt2Pxpd5HAN6eb1z1XPlEmaYO0FuTh/j+78YCC8AZRpdrN5xJu 8K8xITVV4ttAskJsqY7cH/aDd47IQs6JSYkn6tUveGUPf/6Bh7oaT6uZrv+bwaq+5kso wZifMPMnbk8fqL9pDCo7/zMrXifCbeP4C+3g8o73QYSGeD6gnPEKIlDHBQiKlfTsIJAO Kt9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=SgyXWIvRtBQKlUq9mBeiJwHxh+LLhPqX7J4QDpZqGM4=; b=CDvUPV19VEQwffGm5wNW/vfMrVYysjHNhQb2gH9nql1BMqlcd242/qqhGu7VPhYQvS 4xfLBWorPoBML8LHU2FrtjNBp2IEPly7wonxLZ09WPQHPU0Mu/5A1FVgM52vwE/1Mb9p dAsdG5l+KJ3sA6KFVV3NhkgN8O3RdXHK1WF+eF0iBiJTH+AbdmMXaB7KPAm/wAKZXio3 k0Li8R4uuWrH5oSkBkDAiiGzNpY08DihIww7jQzowPzSTPlRyiqW+iwuQ4a1QUEP2unc 1v0gewqzdj1dlJuc8D63AYyJSXdlyXUBFj0++psjKaMEdrwP7Vd2D/EQeSjoN7taNK5l CBow== X-Gm-Message-State: AOAM530weqBEs8F+Mr/WLBDkEjpR+mkameihU0uMQumqYVWQ8tcUSxVB NACKmrSRc0wVUln2M47L1eYffVB4yew= X-Google-Smtp-Source: ABdhPJzHcHkClwWCfw530UEtxeGixmt5X6EhmbLX7mgVwJRWS9F4xGtB00COn9u9C5PTH/MlxCfSuw== X-Received: by 2002:a1c:a706:: with SMTP id q6mr2914107wme.7.1607418669572; Tue, 08 Dec 2020 01:11:09 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id j6sm18559948wrq.38.2020.12.08.01.11.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 01:11:08 -0800 (PST) To: internals@lists.php.net References: Message-ID: Date: Tue, 8 Dec 2020 09:11:05 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Enumerations From: rowan.collins@gmail.com (Rowan Tommins) On 07/12/2020 20:20, Max Semenik wrote: > I myself have tried to draft my proposal athttps://wiki.php.net/rfc/enum_v2 which has > aspects both similar and different from yours. I'm afraid that proposal would be a strong -1 from me, as "fancy constants" are my least favourite type of enum. In particular, this would be a deal-breaker: > Conversion from other types is not checked, thus enums can hold values > not covered by their constants. The main reason I want enums is to make it impossible to represent invalid states, so that they don't have to be accounted for at run-time. Allowing someone to write (Month)13 without an immediate error would completely invalidate that purpose. > * Performance concern: I suspect that most developers will not use the > advanced features from this proposal and your future plans much, instead > they will want to use it in very simple contexts, e.g. > "$order->calculateWeight(Weight::Gross)". Would every such call require an > object allocation and initialization? What about comparisons, would > expressions like "if ($cardType === Suit::Clubs) ..." require a new object? As I understand it, Weight::Gross just looks up the same object each time, so no allocation would be needed unless this happened to be the first time you'd mentioned that enum. Once you have an instance of an object, you're just passing around or comparing a pointer (i.e. an integer) anyway, so I would expect it to have roughly the same performance as passing or comparing a bare integer. Regards, -- Rowan Tommins (né Collins) [IMSoP]