함수 내부에 외부 변수를 호출 하기 위하여 global 을 사용하는데...

이걸 구분별로 global 여러개 하는것에 대하여 어떻게 생각 하세요?
예를들면
# 이해를 돕기위한 예제입니다. 실제 사용되지 않습니다.
function test() {
// 그누 보드 환경변수 Global
global $g5, $config, $member, $board;
// 코어 환경변수
global $Core, $CoreMember;
// 클래스 변수
global $TbClass, $CoreClass;
if( $member['mb_id'] != $CoreMember['mb_id'] ) {
return true;
}
else {
return false;
}
처리문 ~~~~~
}
좋은 의견 부탁 드립니다.~~

댓글 10개
//php 4
class global_test
{
var $g4;
var $member;
var $config;
function global_test()
{
global $g4;
global $member;
global $config;
$this->g4 = $g4;
$this->member = $member;
$this->config = $config;
}
}
$global_test = new global_test();
function test()
{
global $global_test;
echo $global_test->g4['path'];
}
이런식으로 변수하나만 넘기거나,
class global_test_extend extends global_test
{
function global_test_extend()
{
parent::test();
}
function check()
{
echo $this->g4['path'];
}
}
클래스 에서는 상위 클래스 그냥 상속해 버리는데요.
class global_test
{
var $g4;
var $member;
var $config;
function global_test()
{
global $g4;
global $member;
global $config;
$this->g4 = $g4;
$this->member = $member;
$this->config = $config;
}
}
$global_test = new global_test();
function test()
{
global $global_test;
echo $global_test->g4['path'];
}
이런식으로 변수하나만 넘기거나,
class global_test_extend extends global_test
{
function global_test_extend()
{
parent::test();
}
function check()
{
echo $this->g4['path'];
}
}
클래스 에서는 상위 클래스 그냥 상속해 버리는데요.
php5
config_class
{
public static $g4;
public static $member;
public static $is_admin;
public satic $board;
public function __construct()
{
global $g4;
global $member;
global $is_admin;
global $board;
self::$g4 = $g4;
self::$member = $member;
self::$is_admin = $is_admin;
self::$board = $board;
}
}
/lib/latest.php
function latest(...)
{
echo config_class::$g4['path'];
}
config_class_test extends config_class
{
public function __construct()
{
parent::__construct();
}
function test()
{
echo self::$member['mb_id'];
}
}
php5 가 되면 이건 좀 편해지더군요.
5.3 이 되면 많이 복잡해 져서 아직 거기까지는 못써봤습니다.
config_class
{
public static $g4;
public static $member;
public static $is_admin;
public satic $board;
public function __construct()
{
global $g4;
global $member;
global $is_admin;
global $board;
self::$g4 = $g4;
self::$member = $member;
self::$is_admin = $is_admin;
self::$board = $board;
}
}
/lib/latest.php
function latest(...)
{
echo config_class::$g4['path'];
}
config_class_test extends config_class
{
public function __construct()
{
parent::__construct();
}
function test()
{
echo self::$member['mb_id'];
}
}
php5 가 되면 이건 좀 편해지더군요.
5.3 이 되면 많이 복잡해 져서 아직 거기까지는 못써봤습니다.
저는 아래처럼 지정해서 사용한지 오래됬는데 사용상에는 문제는 없는것 같습니다.
하지만.... 글로벌에 너무 많은 함수가 담겨있음으로... 네임스페이스 단위로 끊어서 상호 extend 시켜서 필요한 환경 변수만 호출 하도록 하는게 좋을것 같다는........................................... 생각만 1년 내내 하고있는데 방법을 잘 몰라서 ㅋㅋㅋㅋ
코드이그나이터를 좀더 연구 해봐야지요 ㅋㅋㅋ
// 기본함수 로드 처리 및 벤치 마크 기본설정
public function __construct(){
$this->benchmark_start = 0;
$this->benchmark_stop = 0;
$this->Sysload();
}
// 기본 공용 함수 설정
protected function Sysload(){
global $g4, $config, $member, $root, $shop_config, $user_data_folder, $total, $shop, $sell, $job, $news, $school;
$sms_config = sql_fetch("select * from xe_sms2");
$this->g4 = $g4; // array
$this->job = $job; // array
$this->root = $root; // array
$this->shop = $shop; // array
$this->sell = $sell; // array
$this->news = $news; // array
$this->config = $config; // array
$this->member = $member; // array
$this->school = $school; // array
$this->pay_type = $pay_type; // TEXT
$this->sms_config = $sms_config; // array
$this->shop_config = $shop_config; // array
$this->user_data_folder = $user_data_folder; // TEXT
}
하지만.... 글로벌에 너무 많은 함수가 담겨있음으로... 네임스페이스 단위로 끊어서 상호 extend 시켜서 필요한 환경 변수만 호출 하도록 하는게 좋을것 같다는........................................... 생각만 1년 내내 하고있는데 방법을 잘 몰라서 ㅋㅋㅋㅋ
코드이그나이터를 좀더 연구 해봐야지요 ㅋㅋㅋ
// 기본함수 로드 처리 및 벤치 마크 기본설정
public function __construct(){
$this->benchmark_start = 0;
$this->benchmark_stop = 0;
$this->Sysload();
}
// 기본 공용 함수 설정
protected function Sysload(){
global $g4, $config, $member, $root, $shop_config, $user_data_folder, $total, $shop, $sell, $job, $news, $school;
$sms_config = sql_fetch("select * from xe_sms2");
$this->g4 = $g4; // array
$this->job = $job; // array
$this->root = $root; // array
$this->shop = $shop; // array
$this->sell = $sell; // array
$this->news = $news; // array
$this->config = $config; // array
$this->member = $member; // array
$this->school = $school; // array
$this->pay_type = $pay_type; // TEXT
$this->sms_config = $sms_config; // array
$this->shop_config = $shop_config; // array
$this->user_data_folder = $user_data_folder; // TEXT
}
게시글 목록
| 번호 | 제목 |
|---|---|
| 18790 |
JavaScript
공백제거
|
| 18788 |
PHP
셀렉트박스 간편하게 만들기
1
|
| 18786 | |
| 18783 |
PHP
게시판의 페이징 방법
2
|
| 18780 |
PHP
이미지에 워터마크 처리하기
2
|
| 18769 |
Mobile
Chrome 를 이용한 모바일모드
10
|
| 5549 | |
| 27272 | |
| 27267 | |
| 30785 | |
| 30782 | |
| 27264 | |
| 18767 |
JavaScript
스크립트오류 제거
1
|
| 18765 |
JavaScript
간단한 쿠키지원 팝업 스크립트
1
|
| 18764 | |
| 18763 |
JavaScript
대소문자변환
|
| 5546 | |
| 18760 | |
| 18758 | |
| 18755 |
JavaScript
홈페이지 브라우저 크기 고정시키기
2
|
| 18752 |
JavaScript
iframe 아이프레임 투명처리
2
|
| 27256 | |
| 27247 | |
| 5539 | |
| 18750 | |
| 27244 | |
| 27243 | |
| 18749 |
JavaScript
금액 입력시 자동으로 천단위구분기호(,) 붙여주는 함수
|
| 18747 | |
| 18745 |
JavaScript
출생년도에 따른 나이 계산 자바스크립트
1
|
| 18741 | |
| 18740 | |
| 18738 |
JavaScript
iframe에서 페이지를 닫을 때
1
|
| 18731 |
JavaScript
iframe 높이 자동조절 스크립트
6
|
| 18730 |
JavaScript
자바스크립트 인공지능 장기게임-Minimax
|
| 27240 | |
| 5535 | |
| 18728 |
JavaScript
금액을 한글로 표기 해주는 스크립트;
1
|
| 18726 |
JavaScript
전화번호 입력시 자동 하이픈 넣기
1
|
| 18724 |
JavaScript
사업자번호체크스크립트 간단버전
1
|
| 5532 | |
| 26500 |
견적서
홈페이지 제작 견적서
14
|
| 27237 | |
| 5529 | |
| 30776 | |
| 18721 |
jQuery
플러그인 만들기 간단 예제
2
|
| 20725 | |
| 27232 | |
| 18719 |
JavaScript
퀵메뉴
1
|
| 18717 | |
| 18714 |
JavaScript
입력박스안에 왠 아이콘?
2
|
| 18712 |
JavaScript
게시판 글작성시 일부 태그막기
1
|
| 18709 |
jQuery
랜덤한 레이아웃과 효과
2
|
| 27213 | |
| 27200 | |
| 18706 |
JavaScript
자동으로 textarea 크기 조절하기
2
|
| 18704 |
JavaScript
textarea 자동 늘려주기 2
1
|
| 18702 |
JavaScript
해당 브라우저에 지원하는 이벤트 확인
1
|
| 18701 |
JavaScript
자바스크립트로 논리적인 XOR 연산하기.
|
| 18700 |
JavaScript
동적 셀렉트박스 다루기.
|
| 18698 |
JavaScript
자바스크립트 이벤트 핸들러 (Event Handler)
1
|
| 18697 |
JavaScript
함수명을 변수로 해야할 때
|
| 18696 |
JavaScript
이메일 유효성 정규식 - 자바스크립트
|
| 18694 | |
| 5525 | |
| 27199 | |
| 18691 | |
| 5515 | |
| 5510 | |
| 5501 | |
| 18690 | |
| 18687 | |
| 5496 | |
| 18686 | |
| 18676 | |
| 26496 |
서식
영수증 양식
3
|
| 18675 | |
| 30773 | |
| 18671 |
JavaScript
이미지 슬라이드 관련입니다.(자바,제이쿼리)
3
|
| 30767 | |
| 18667 |
JavaScript
롤오버시 서브메뉴가 나타나는 기본 스크립트
3
|
| 18658 |
jQuery
회사에 히스토리에 써먹을 만한 자료
8
|
| 18650 | |
| 18648 |
MySQL
고수님들 도와주세요!
1
|
| 5494 | |
| 5490 | |
| 20705 | |
| 5485 | |
| 18645 |
Mobile
json 파싱방법
2
|
| 27194 | |
| 20684 |
정규표현식
정규표현식 의 핵심. 패턴변경자 1
20
|
| 18642 | |
| 5482 | |
| 27185 | |
| 5478 | |
| 5473 | |
| 5467 | |
| 18636 | |
| 5462 | |
| 5443 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기