Proposal for 2 new magic constants
| From: | php at s22 dot us | Date: | Sat, 23 May 2026 16:38:48 +0000 |
| Subject: | Proposal for 2 new magic constants | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-130990@lists.php.net to get a copy of this message | ||
Hi all,
I would like to propose two new magic constants to PHP: __HOME__ and __USER__
These would allow us easy ways to get the following information in our scripts:
Constant Results
__USER__ username
__HOME__ /home/username
To get that info now we have to resort to things like:
define('HOME_PATH', implode('/', array_slice(explode('/', __DIR__), 0, 3)));
define('USER_NAME', explode('/', HOME_PATH)[2]);
Personally, I use these a lot and it would be nice to call a simple constant instead of a line of code. I think others could benefit from them, as well, hence my proposal.
So, I'd like to hear what others think before presenting an RFC. Do they sound beneficial to anyone else?
Thanks,
Marc
P.S. Hopefully I'm posting this to the correct list. If not, please point me to where I need to be.