Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107980 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92115 invoked from network); 3 Jan 2020 20:51:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2020 20:51:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B813F180559 for ; Fri, 3 Jan 2020 10:55:31 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 ; Fri, 3 Jan 2020 10:55:30 -0800 (PST) Received: by mail-yb1-f182.google.com with SMTP id f136so15867833ybg.11 for ; Fri, 03 Jan 2020 10:55:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=HPDgT4G5Fa5V6ouqlFaSUStPJBxpSor6m4o7DTpP/wM=; b=okCFts9zUpxeYCeHjeMNQg3isI5YJh/K8ax+JjAYs0+k0PFcwlYmrznfNSuaa+iCpZ MzUFiVa3zT/LfV4+MPg/5tN3GgVvdvrhpZrWEZgJ0+P8wh9t/YQG9ufXtPDq/Eznh/QK mRekvgSppjT8sDSs2RWkdT0moKf3mTdXAbNLvEV6+alszQP3xSvOwfvxi5nL1RJru+tG +l4xXLy1DaJmRziW3IDX300H70W2OXWNklZ/OhoOE9sGynIp2WYE1gqeC65kRdERRz49 UoyEyE39E+Tm3E63rc2mgzuROZ6r4h0kIO5TJ14aAGk5LBzFHSj0NBA9Nz14Owb+y9Jb jOMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=HPDgT4G5Fa5V6ouqlFaSUStPJBxpSor6m4o7DTpP/wM=; b=RcyNr5xSeicX86GnS6Ry90GWR1Bqk05+YTUNV1pc18sg6h3Okkc9l8IcR62gBDH+F7 ijLBj64qfS8FxSERA8YxMwoVlPz3UrhbKI+9bXgi8px7i/qsxd0F2q9A2zYLh+gDK4Zr rvC1/7TDzK4ZlbLw1Q9cPwygXdjtmfa1p51LBiqOSrUBWrGOarNMQEpjbjHQAgb5QE3y NnV4U0VELmdvmkNUWSu5oXpBofAi7Qteh+Jc8kVplJPmiP/yJyGvheDIi8CcPgWlkE8i zpuiduahTvKCvSFhsX7O3h0AJ8oepaseg5xntvJmZVj4AsBcW7AYsF2n0GllbYMQVKEF DjQA== X-Gm-Message-State: APjAAAWEgi2xLg+RPs522g3TYAa5vdjwTrl5y4wHf6NmA0epRC+WRtej fOiENo/4qryBkWJ3ltz9Mh5nVg== X-Google-Smtp-Source: APXvYqwbyKipcoONR+drl3lw0UYWh4j8ncgE5mOh/34NIjflHo2uLFSYRssnsJnlg5MF3wbcUzdkXg== X-Received: by 2002:a25:44d7:: with SMTP id r206mr43406416yba.256.1578077728551; Fri, 03 Jan 2020 10:55:28 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:b4a8:a0ad:705d:1ec8? ([2601:c0:c680:5cc0:b4a8:a0ad:705d:1ec8]) by smtp.gmail.com with ESMTPSA id 205sm24194889ywm.17.2020.01.03.10.55.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jan 2020 10:55:27 -0800 (PST) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_1F9F0A5A-8DDA-48C0-B0C7-7F51FB2C3EF4" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Fri, 3 Jan 2020 13:55:26 -0500 In-Reply-To: Cc: php internals To: Larry Garfield References: <5e0d723f.1c69fb81.e2ae8.24e2SMTPIN_ADDED_MISSING@mx.google.com> <74F2DBFC-E63C-428C-A37F-2D0CEE15AD0F@newclarity.net> X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Initializing constants once, with code? From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_1F9F0A5A-8DDA-48C0-B0C7-7F51FB2C3EF4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi Larry, Thanks for replying. > It seems to me it would be much cleaner to just... build that into a = static method call with the derivation-and-caching logic behind the = scenes. It's not complicated code. That is exactly what I have been doing, and what I am finding = suboptimal. The problem is that, most of the time and especially when refactoring = poorly written code, we just want a constant. One line in the class = file, hard coded. =20 We ideally don't want to have to write a full functionr. So for five = data elements, 5 easy to read lines of code with constants vs. 20 harder = to read lines with functions, or at least 40 lines if we include PHPDoc = for those functions, which is part of our standard for writing = functions. When we *later* want to be able to refactor to initialize with code we = want to do so w/o having to modify the code that is already using the = constants. But we many never actually need to do so. What I am asking = for is the option. Basically, in my view, a programming language is better if it can = support refactoring a reusable unit of code to add additional = functionality W/O requiring the code that uses the reusable element to = be modified. Using your proposed approach we cannot start using = constants and later move to functions unless we modify all code that = uses those constants. That is Bad JuJu(tm) in my book. OTOH, if PHP 8.x would allow functions w/o parameters to be called w/o = parenthesis then your approach satisfy the use-case: class Stuff { protected $val; public static function VAL() { self::$val ??=3D computeStuff(); return self::$val; } } echo Stuff::VAL; //<=3D=3D if this could work then using functions = would address the use-case. > I agree with the use case, but not with the solution of piggybacking = them onto constants.=20 Let me put it more concretely. What I am asking for is this: > "Transitionally of reusable code when using constants that does not = require modifying code that already uses the constant." So using functions does not actually address the use-case I am = identifying. Is there some technical reason why you object to extending constants, or = is it your objection more stylistic? -Mike --Apple-Mail=_1F9F0A5A-8DDA-48C0-B0C7-7F51FB2C3EF4--