On Fri, Jan 3, 2020 at 8:55 PM Mike Schinkel <m...@newclarity.net> 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 <https://azonmedia.com/> and Guzaba Framework <https://github.com/AzonMedia/guzaba2>