Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108071 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39117 invoked from network); 9 Jan 2020 22:22:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 22:22:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 19BC9180505 for ; Thu, 9 Jan 2020 12:28:15 -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,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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 ; Thu, 9 Jan 2020 12:28:14 -0800 (PST) Received: by mail-yb1-f171.google.com with SMTP id o199so1405178ybc.4 for ; Thu, 09 Jan 2020 12:28:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=8kmHxpD8IdQctXYa05NRyzFPvsum1+vcUZn+6Mo4/UI=; b=oqNbHWy+auEYipoQlrGH9vMhKpSZcE+n6zMoefj+Fur34WnNLhQa5mVhUxIqYdM/D2 6BqjJpZizedjr6Mk2xDpp7gPdpLGoS2v6u65CO3i9Xe3HYf8/fRFnUBasg3Mkq4PWK5z iuD7ujNR9Iun2WI9Sm4TNi8IJCWREA+VudTEpepRCIpb0sSAWwI0qxNoGxwB6YtDjpnI VuXa1KQuOII1cBl6GtSpqQkK6j1CEUfEHaOjpSp+Xp2KMJA5+DfbJKs6JDKoorEtaQhQ eT1fl2e9Uw/KpRCx8qMXSQHvMq3RON9gNAoPxsVCmzWINZDwHU0w1tMwPLr36Si2CxhO CFEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=8kmHxpD8IdQctXYa05NRyzFPvsum1+vcUZn+6Mo4/UI=; b=ov1urAvietRpjNYGGKksAfkOSosPasaGwp07sBZCboTZdd7taa9jUMJrPjIFz1uiid YjYZEzS6+gdWMrOrxdU3zF0PrUJ2y6KnNuZ9/TJS5TobsLjEpE76OR4pN6XcnAb9OszX LXrvWxT2ltT8POmglAZn4BL9UxcXyjXCinaWLvCLOr5UkYTwiNFh+2NJ6GISFeurzFlm nxuqjpS623RGuGLkqcbPFSDg899WdFtThkjp41DfoxnzPhEzcI4I/MoSXw+5frOL7yM4 jDOalL5hT1pzBjJzf9OgHo/FF5up+mKeOTv+QVbcfeMcK7h1UsECJLtHSqjWt2VvWCJ0 VHoA== X-Gm-Message-State: APjAAAUDhD8rZTNhUI306HJInOBST+J4PDzDw5o3Z47SWULOnI5EbNDF DK5Iv4Q+5Pcp4YlnMzHb6sExJQ== X-Google-Smtp-Source: APXvYqyHjGdvBhVZK6RYED716yjayO+/GiVyyKA+54fXvLWBRHVEjtUsip5FGOKsHUiWz4Z2546dbg== X-Received: by 2002:a25:d648:: with SMTP id n69mr8925363ybg.216.1578601693499; Thu, 09 Jan 2020 12:28:13 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:480:e2c0:f7b2:a682? ([2601:c0:c680:5cc0:480:e2c0:f7b2:a682]) by smtp.gmail.com with ESMTPSA id h68sm3422069ywe.21.2020.01.09.12.28.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jan 2020 12:28:12 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Thu, 9 Jan 2020 15:28:10 -0500 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <106024FC-F36B-4E4E-9383-6430025A8D60@newclarity.net> References: <5e0d723f.1c69fb81.e2ae8.24e2SMTPIN_ADDED_MISSING@mx.google.com> <74F2DBFC-E63C-428C-A37F-2D0CEE15AD0F@newclarity.net> <53556dfb-44ce-f902-204c-9a7da9484a61@gmail.com> <65567C7C-CF0F-4562-8943-F1F302134B07@newclarity.net> <6f20bda1-eff6-631d-915f-d6bb149ee666@gmail.com> <93BA4B49-9D9A-4A41-83B3-8EC2564A70BF@newclarity.net> To: Rowan Tommins X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Initializing constants once, with code? From: mike@newclarity.net (Mike Schinkel) > On Jan 9, 2020, at 4:38 AM, Rowan Tommins = wrote: > Sorry, I don't see it that way. To my mind, the universal use case = here is > "initialise some value once and then access it from the program"; the > syntax is secondary to that. >=20 > Evidently, you see those priorities differently; I don't think we're = ever > going to agree on that. Your "disagreement" has the effect of either ignoring or dismissing the = use-case that was the primary motivation for me to make this request. If you want to dismiss my use-case at least please do so explicitly. > What aspects am I dismissing? I absolutely agree that an equivalent to > Java's final variables would implement your use case - if you were = willing > to relax your syntax constraint. But your proposal is not to have = immutable > variables, as you've said yourself. You ask me to explore what other languages do. I explain that Java use = `static final` to create constants which you can declare them = dynamically.=20 You then claim that since constants are declared as final variables they = are variables. Which is true, but they are also dynamically initialized = constants. But then redirect to discussing PHP variables, which unlike = Java have incompatible syntax to variables and thus cannot address my = primary use-case. Basically you asked me to give an example where constants are = dynamically initialized, so I did, and then you claim those are just = finalized variables. Which they are. But they are also dynamically = initialized constants. Conceptually the difference is academic. If I gave you an example of a compile time constant than it would be = equivalent to PHP and unable to be initialized dynamically. If I gave = you an example of a dynamically-initialized constant then yes, it is = going to be a finalize variable. So effectively you set a trap for me = that I could not satisfy, a catch-22.=20 Would you have accepted my example as evidence of other languages having = dynamically-initialized constants instead if Java had used the `const` = keyword instead of using `static final` keyword, but with identical = implementation? Or will you only accept compile time constants as an = example, which by definition disallow initialization? =20 See the catch-22, and hence the distinction without a difference? > See my my earlier comment about implementation - I'm not sure how we'd > define valid values so that they definitely couldn't be mutable. You = could > restrict to just scalars, but that would then be a tighter restriction = than > actual constants - "const A =3D [1,2,3];" is valid right now,=20 Currently this does not work, so I do not see where the problem is: class Foo { const BAR =3D [ 1,2,3 ]; } Foo::BAR[0] =3D 9; // PHP Fatal error: Cannot use temporary expression = in write context > so preventing that being set dynamically would feel odd. Did not propose that. You can currently initialize const to an array now, and const arrays are = currently immutable. That would not need to change. Further, we continue to disallow initializing const to objects, even = dynamically. No change there. So where is the issue? > Perhaps I'm using the wrong terminology, Probably, at least for me. For decades I have know "pre-processor" to = mean textual substitution. Maybe the newer hipster developers have = redefined that term to mean something else, but I when I hear = "pre-processor" I just think of pattern replacement in text. (Note I am just being tongue-in-cheek about "hipster." No real insult = is intended. :-) > but I think we're talking about the same thing: something that runs = before the > main program, which takes certain parts of the code, interprets them = in some > way, and combines them with the rest of the program. In that context, I am open. > So: an interpreter that runs during preloading, which takes special = blocks of code, > runs them as PHP, and then combines the results into the AST/OpCode > representation of the program. That actually sounds like the brilliant suggestion from Robert Hickman = to consider the equivalent of compile-time code from the Jai programming = language. If you have not watched these =E2=80=94 which I included again = from Hickman's email =E2=80=94 I urge you to watch them as how Jai works = with it's compile-time code execution really is brilliant: - https://www.youtube.com/watch?v=3DUTqZNujQOlA. // Starting at 39:20 - https://www.youtube.com/watch?v=3D59lKAlb6cRg > I stand by my comment that this has *some* of the same problems as a > separate "build" script, such as the need to be configured correctly, I find repeating of this as overstating the concern simply because any = programming language feature would need to be used correctly. So this = also feels like a distinction without a difference. > the difficulty of debugging errors in this special code, Depends? If this where to use XDEBUG just like regular PHP there would = be zero difference. > and the need to invoke the extra processing manually for things like = command-line scripts. Since PHP is different from a pre-compiled language like C or Go, it = compiles "on-demand." So I would see zero need for a build step.=20 I would also see PHP could first run the compile-time code once, and = then run the runtime code for every execution. On-demand. And XDEBUG = could be used for both. For CLI, it might always run the runtime code and then the compile time = code. Unless there is a standard location set of compiled opcode in .ini = file, and/or unless PHP provided ways to generate OpCode artifacts to be = loaded at runtime. -Mike