Zend certified PHP/Magento developer

Please do not pass the “Allow function calls in constant expressions” RFC

https://wiki.php.net/rfc/calls_in_constant_expressions

As team lead and professional code reviewer, I spend roughly 50% of my day reviewing mostly PHP code. One of the fundamental assumptions we have been able to make since the introduction of const FOO = 1234; is that no matter what, we could always see what was on the right side of the equation and it would always be, well, constant. No matter what changed in the database, the web, whatever, that value will always be 1234.

All of the examples in the RFC are NOT idempotent and very well will return different results when passed in the same context. For instance, on one page load count(self::PAGES) might be 5, another, 50, another 0 [now you have unexpected divide-by-zero errors].

tl;dr: This RFC breaks critical and time-held doctrines that 1) const will be const forever, under every circumstance until the developer changes the code’s value, and 2) PHP doesn’t automagically cache any variables. Implementing this RFC will lead to greatly increased cognitive load for everyone who reads PHP professionally (all of us).

For setting “the default values of static properties” and “Parameter defaults “, I would absolutely love and have been wanting for years. In those scenarios, we never ever expect static properties nor parameters to be constant so none of the above applies.

However, “Defaults of static variables (evaluated and cached the first time the expression succeeds)” < -- This would be the very first time and only place that a variable is artificially cached. This would be a code review nightmare and increase cognizant load even more than global constant changing with each load.

In closing: Over the years, I have witnessed many of these RFCs proposed (and mostly accepted) that increase the cognitive load of reviewers of code and also people just reading it, while doing little in the balance that justifies the expense. For instance the spaceship operator (< =>). How often have you really used it? (Me? 2x in 5 years) Yet, it greatly increases cognitive load over the if / else alternative before it.

Let’s not have yet another one. Implement the default static properties and parameter defaults, that’d be awesome. But leave const alone and please, pretty please, don’t start automagically caching any variables anywhere, at least without a huge community-wide vote.

And can we the community actually start getting 25% of the vote on all these things? i’m tired of my entire career resting entirely in the hands of unelected people who not only don’t represent me (or anyone) in the greater PHP dev community, but the vast majority of whom are great C coders but maybe have never managed a team of actual PHP developers any time in the last 5 years.

(I’ve been developing apps in PHP since PHP/FI v2.0 in March 1998 since I was 15 and I plan to code in it primarily for the rest of my life. i’m so thankfulr for Rasmus, Gutmans and Zeev and NickiC and SaraG, and esp whomever invented composer. OHHHH And Taylor Otwell for the amazing framework I have fine tuned my career around, anddddd Sebastian Bergmann who’s PHPUnit keeps me honest and the guys behind PHPStan for increasing the integrity of my code. And JetBrains, who’s PhpStorm and DataGrip really brought back the enjoyment of coding for me.)

submitted by /u/2012-09-04
[link] [comments]