note 117643 deleted from function.return by peehaa

From: Date: Sun, 28 Apr 2019 10:28:04 +0000
Subject: note 117643 deleted from function.return by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210786@lists.php.net to get a copy of this message
Note Submitter: brad dot k dot harms at gmail dot com ---- I wonder if return in the global scope would be a semantic way to store low-level, pure-PHP config arrays while avoiding polluting the global scope. For example: <?php // app.php function app() { $conf = include('conf.php'); } app(); <?php // conf.php return [ 'db' => [ 'host' => '127.0.0.1', 'username' => 'user', 'password' => 'pass' ], ]; ?> This approach produces exactly 0 global variables. (PS. I also tried this using a JS-like module pattern using an anonymous function but it seems that an anon function can't be defined and called in the same expression.)

« previous php.notes (#210786) next »