Re: RFC: autoconst

From: Date: Sun, 01 Aug 2021 11:41:59 +0000
Subject: Re: RFC: autoconst
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-115616@lists.php.net to get a copy of this message
> > Hello! > > This is my first RFC proposal. I have an idea about introducing autoconst keyword. > Motivation: > reduce duplicated code (copy/pasting constant name as value) > reducing potential typo errors in constant values > > instead of defining constants like: > const FOO = 'FOO'; > > they could be defined like: > autoconst FOO; // defines a constant FOO with the value 'FOO' > > Also, modifiers could be useful: > autoconst uppercase foo; // defines a constant foo with value 'FOO' > autoconst lowercase FOO; // defines a constant FOO with value 'foo'; > > and maybe: > autoconst camelcase FOO_BAR; // defines a constant FOO_BAR with value 'fooBar' > autoconst snakecase fooBar; // defines a constant fooBar with value 'foo_bar' > > could be listed like: > autoconst FOO, BAR, BAZ; > autoconst lowercase FOO, BAR, BAZ; > > What do you think about that? If you like my idea, I would request a karma for creating this > RFC in the wiki. Hope you'll like the idea! Hi Serhii, With Enums supported in PHP 8.1, I think this pattern of using constant names with identical values will see fewer use cases. I also don't think that a proposal to add new common keywords like uppercase / snakecase, or adding any magic to constant names (because PHP 7 supported case-insensitive constants) will be received well either. Thanks, Ayesh.

« previous php.internals (#115616) next »