Created
August 19, 2013 21:52
-
-
Save hirak/6274617 to your computer and use it in GitHub Desktop.
グローバル変数を作らずにファイル間で値をやり取りする ref: http://qiita.com/Hiraku/items/551ba8bf15b6b23a12a6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace My\Temp; | |
if (!function_exists('My\Temp\getConfig')) { | |
function getConfig() { | |
static $config; | |
if (!$config) { | |
$config = ['hoge' => 'fuga']; | |
} | |
return $config; | |
} | |
} | |
return getConfig(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//値を使いたい場合はrequire式を埋め込む | |
var_dump(require 'config.php'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
var_dump(require_once 'config.php'); //['hoge'=>'fuga'] | |
var_dump(require_once 'config.php'); //true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment