Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107981 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 553 invoked from network); 3 Jan 2020 21:45:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2020 21:45:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D60B718055B for ; Fri, 3 Jan 2020 11:49:24 -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=-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,SPF_HELO_NONE,SPF_PASS 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-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 11:49:24 -0800 (PST) Received: by mail-wm1-f42.google.com with SMTP id d139so7577433wmd.0 for ; Fri, 03 Jan 2020 11:49:24 -0800 (PST) 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=1BfQ4A+jvep2bKBqN/d13ifCR+XDdFc+FXDgMUxhtTM=; b=SNBU3aRX6RC9V26LvReOfy5Igas1slrsyRDaiviCJ3EMhppGKRRxNgOeoyMn2rEz56 DsQgwoXKgeZB7J/p1PLQtq6Gt+swUReIG/bvf3tjGATPfpxcSehfEIFLFsf5Ux0n4nwD oRN3KarpIAZKgpagvbOGWcwLkBkKguwr9a65V91qmT5qYv0LDqxRuRdNBD+3UMvsxcG0 6Rj2RxCELGJlcCQoAjojwycgOkDMVSAU4pIEbPk7rbyopwdpWdjMbgUX7d/kMVRME0At L4EZpZvhdq8wxhvnZfpj4jDV9uYEWXhYJVbEwo/qoO3wKWkySyNekkJEKPuTOE+FdR+7 11GQ== 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=1BfQ4A+jvep2bKBqN/d13ifCR+XDdFc+FXDgMUxhtTM=; b=thopRhnkdmRB+YldO8+yG635WCNIAIAaTFrJ6B8DleuYmeFmEXkv7nxD1aa6vO0gt8 mwXJ570lU0ri8dnYAVNugF//bLIeEogtSOk2D+zemIwSp0+CLCSzYi9u8NEN+akHQrjn YCAjtisJ7Ft2NVGslHeTox861s+H1TTKQEhXY0dB4rkLU9qy7eu+IpBOEXelvPK7ipkV 6o8EZAp56MBFSTkfw7LkWsH8zQwpXaqsb1S2BaN1oV2XRzo3+VaaZFu+hFB6HdQXVcMD aInlWcy335duX3VjNkkiNdeNeJbzoFfcrttC1v5UFpAOk7r4M8Ev7FL9oSF2sm8vINIO oPbw== X-Gm-Message-State: APjAAAV+jMlR6CH8hdtWbDskHyBJt+6COaXtHSnpHcXi0miP0jG7c01O IVhA7+UMVI6BM4KkUDEeIk2EOD0Fd2i99j2k0BI= X-Google-Smtp-Source: APXvYqw/dIz8MSnIXFa6whlDqhlt+aBlaRzkFhfsKQ4uw995rzPxlGoleh/txhlyKTgaSRhGB6gu6rJq+E+VUC8sCn8= X-Received: by 2002:a05:600c:290f:: with SMTP id i15mr21552950wmd.115.1578080612905; Fri, 03 Jan 2020 11:43:32 -0800 (PST) MIME-Version: 1.0 References: <5e0d723f.1c69fb81.e2ae8.24e2SMTPIN_ADDED_MISSING@mx.google.com> <74F2DBFC-E63C-428C-A37F-2D0CEE15AD0F@newclarity.net> In-Reply-To: Date: Fri, 3 Jan 2020 21:43:22 +0200 Message-ID: To: Mike Schinkel Cc: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="0000000000005bf6bd059b418666" Subject: Re: [PHP-DEV] Initializing constants once, with code? From: kenashkov@gmail.com (Vesko Kenashkov) --0000000000005bf6bd059b418666 Content-Type: text/plain; charset="UTF-8" On Fri, Jan 3, 2020 at 8:55 PM Mike Schinkel wrote: > ... > > 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 ??= computeStuff(); > return self::$val; > } > } > echo Stuff::VAL; //<== if this could work then using functions would > address the use-case. > > Hi everyone, I just wanted to comment on the above - in my view we can not have someclass::VAL be a constant or a function call of a function that has no arguments. It is not that it just feels confusing but also may create issues as a person may invoke multiple times someclass::VAL thinking that this is a constant (cheap) while in fact it may be a method doing expensive lookup. And my personal feeling is very much against mixing two completely different things in this way. This reminds me of Matlab where A(4,5) may be a function with two arguments, or a matrix lookup (things may have changed since and may no longer be the case...). And on a side note - the described problem I solve it in two ways: - custom autoloader that invokes a initialization method that sets static vars - more recently - a class generator (as mentioned above). This gives no performance hit as Im using Swoole and it happens only at server start. Thanks Vesko -- Vesko Kenashkov Developer at AzonMedia and Guzaba Framework --0000000000005bf6bd059b418666--