Skip to content

Instantly share code, notes, and snippets.

@hirak
Created August 19, 2013 21:52
Show Gist options
  • Save hirak/6274617 to your computer and use it in GitHub Desktop.
Save hirak/6274617 to your computer and use it in GitHub Desktop.
グローバル変数を作らずにファイル間で値をやり取りする ref: http://qiita.com/Hiraku/items/551ba8bf15b6b23a12a6
<?php
namespace My\Temp;
if (!function_exists('My\Temp\getConfig')) {
function getConfig() {
static $config;
if (!$config) {
$config = ['hoge' => 'fuga'];
}
return $config;
}
}
return getConfig();
<?php
//値を使いたい場合はrequire式を埋め込む
var_dump(require 'config.php');
<?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