note 117643 added to function.return

From: Date: Mon, 13 Jul 2015 22:06:57 +0000
Subject: note 117643 added to function.return
Groups: php.notes 
Request: Send a blank email to php-notes+get-203101@lists.php.net to get a copy of this message
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.) ---- Server IP: 72.52.91.14 Probable Submitter: 206.192.195.206 ---- Manual Page -- http://php.net/manual/en/function.return.php Edit -- https://master.php.net/note/edit/117643 Del: integrated -- https://master.php.net/note/delete/117643/integrated Del: useless -- https://master.php.net/note/delete/117643/useless Del: bad code -- https://master.php.net/note/delete/117643/bad+code Del: spam -- https://master.php.net/note/delete/117643/spam Del: non-english -- https://master.php.net/note/delete/117643/non-english Del: in docs -- https://master.php.net/note/delete/117643/in+docs Del: other reasons-- https://master.php.net/note/delete/117643 Reject -- https://master.php.net/note/reject/117643 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203101) next »