Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114865 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58705 invoked from network); 14 Jun 2021 14:45:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jun 2021 14:45:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5A84A180508 for ; Mon, 14 Jun 2021 08:02:02 -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,HTML_MESSAGE, 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-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 ; Mon, 14 Jun 2021 08:02:01 -0700 (PDT) Received: by mail-lf1-f48.google.com with SMTP id p7so21666686lfg.4 for ; Mon, 14 Jun 2021 08:02:01 -0700 (PDT) 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=gZm5/EM1Ab4vEcw3yX0HXzzPiXNKODRVOmAYIzkDGv4=; b=NYLFPMuI8+ds3ay9/sXcZvuqOlZS6QVyVTMyvbaWtUXRMB6/FoiwgkE/aoMgISMZ0Y bCDGg8ectkNFyPJ68SG9Ay9rOk14DzNMFXwJ9awku5TD6YMwrmaK/3j73Ivb+TXfrbar i3TQUuXsxP5hvo+x6zCnTLMGOC7dU2ab/yqtENzSDqFFAzW2Zd3uq+hCcsSNFV+12ja0 324fJ/e/N5jk+ZJdJenCfXYz9Hk+ll2TyUrYLkE1DBR0a6k1ZluC3BcduHNZvNitDHFQ 9wCQaJ/wXhOC8rwxlx3DEyuFgPBwZS5QCYioh34C02vht1aTe6JKHJ3RRzJ0ULX3dFfL W1sg== 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=gZm5/EM1Ab4vEcw3yX0HXzzPiXNKODRVOmAYIzkDGv4=; b=gnbZGXwJxzK/JA4sw8xel2bNlIFNY7IizGY4zQ6U4vVVqp5p2PnhFWtvY0TGMB0gm6 sumHCf3l4lsOonKFSedZl15VaQ8EYdKfJKUeKwbpcNZV4IsIDhhPEMqgo1tNVIAaDWzy uMXy7g4ZXVypXNzPYG+eaQSAhc9c4aC9DErzE3EaSXLgOu7/y7eN9wYjNzvUR20s/1EW Z4BgJ94MtecSEMV76b/D5QErsaRfSnR/Sx4FQ3ZJWASTBSvhZ/E1bMuTv5ZDe6qI2CyN 9c2xW49Rwo0391Obrqdqn+U+w+u6FaKI6YR4A7FmuPKSk9n9RLtGE2uQTBidloUCtOU3 eBvA== X-Gm-Message-State: AOAM530hPIyjo7LzC/1Kv04mdChHiR5ULnk1DNA92+PShur++fIgqfZi PUxaInpHk7AI6cG2wTYCLNiTAu0jYEiVLdU74F0= X-Google-Smtp-Source: ABdhPJyscdjLh2Y/6Pw4D1FLEX32J7uqntv6LRcrcpVkLz8gJKfxtW83M/3AuyFb/jKxtuOFXMxMr2mKMY6DHTd9VcU= X-Received: by 2002:ac2:4acf:: with SMTP id m15mr3782622lfp.286.1623682919793; Mon, 14 Jun 2021 08:01:59 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 14 Jun 2021 17:01:43 +0200 Message-ID: To: Marco Pivetta Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000a98a3005c4bb23db" Subject: Re: [PHP-DEV] Allow objects in define() From: nikita.ppv@gmail.com (Nikita Popov) --000000000000a98a3005c4bb23db Content-Type: text/plain; charset="UTF-8" On Mon, Jun 14, 2021 at 4:42 PM Marco Pivetta wrote: > Hey NikiC, > > On Mon, Jun 14, 2021, 16:35 Nikita Popov wrote: > >> Hi internals, >> >> With the introduction of enums, it's now possible for constants to hold >> objects. However, this works only when using the `const X = Y` syntax, not >> when using `define('X', Y)`, which still excludes objects. >> >> I've submitted https://github.com/php/php-src/pull/7149 to relax the >> restriction. This means that define() would accept everything apart from >> recursive arrays. >> >> An alternative here would be to allow define() to only accept enum objects >> in particular, but not other objects. I would prefer not to do that, as >> such a restriction would be rather arbitrary, now that the technical work >> to support objects has been done. (PS: Please keep the difference between >> mutability and interior mutability in mind.) >> > > I rarely encounter any code using `define()` for anything more than > extremely minimal environment details these days, and even then, it usually > leads to loading an immutable `Environment` object that is then passed > through dependency injection (container or not) to runtime services. > > What are the possible use-cases for this, besides enumeration types? > Not sure about specific use cases, for me the important aspect here is to avoid arbitrary restrictions. For example, define() accepts resources, and this is used for some core constants like STDIN, STDOUT, STDERR. In the future, we're going to switch these resources to be objects, so allowing them in constants would be necessary at that point at least. Actually, we already encountered this as a BC issue when switching some other resource types to objects. I don't think there is any principled argument for why constants would accept arbitrary resources but not arbitrary objects. There's only the historical circumstance that objects weren't supported for technical reasons, which have since been addressed. Regards, Nikita --000000000000a98a3005c4bb23db--