note 128560 added to function.define

From: Date: Sat, 20 May 2023 17:33:11 +0000
Subject: note 128560 added to function.define
Groups: php.notes 
Request: Send a blank email to php-notes+get-220514@lists.php.net to get a copy of this message
As from PHP 7 constants can be arrays there this is a great way of storing application settings. Constants are global all by themselves and for a simple application, without OOP constants settings are a great way to make them available globally: <?php declare(strict_types=1); if(!defined('SETTINGS_FILE')) { define('SETTINGS_FILE', $_SERVER['DOCUMENT_ROOT'] . '/settings.ini'); }; class Settings{ public static function getSettings(): array { return parse_ini_file(SETTINGS_FILE, true); } } define('SETTINGS', Settings::getSettings()); ?> I use a class here to prevent too much exposure but a normal function or lamda would probably do as well. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 83.97.81.249) ---- Manual Page -- https://php.net/manual/en/function.define.php Edit -- https://main.php.net/note/edit/128560 Del: integrated -- https://main.php.net/note/delete/128560/integrated Del: useless -- https://main.php.net/note/delete/128560/useless Del: bad code -- https://main.php.net/note/delete/128560/bad+code Del: spam -- https://main.php.net/note/delete/128560/spam Del: non-english -- https://main.php.net/note/delete/128560/non-english Del: in docs -- https://main.php.net/note/delete/128560/in+docs Del: other reasons-- https://main.php.net/note/delete/128560 Reject -- https://main.php.net/note/reject/128560 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220514) next »