2016-06-22 5 views
0

그래서 내가 메인 클래스 전 클래스를 정의PHP에서 클래스가 있는지 어떻게 확인할 수 있습니까?

function __construct(){ 
    $this->conf = $GLOBALS['conf']; 
    $this->dbi = new dbinfo; 
    $this->modOpt = new modOptions; 
    $this->lang = new language; 

    /** Connect DB extended Class **/ 
    parent::__construct($GLOBALS['connect']); 
} 

에서 구조체 기능의이 종류가 있지만,이 클래스가 포함되어 있습니다 제외한 파일의 시작에 포함되어있는 라이브러리 파일에있을 때 POST 요청 것 다음과 같이 나타납니다

그렇게
if (isset($_POST['delGroup']) && isset($_SESSION['content_viewer']) && $_SESSION['content_viewer']['code'] >= 1){ 
    include_once(realpath(dirname(__FILE__) . '/../..')."/mod/dbinfo/proc.php"); 
} 

내가이

function __construct(){ 
    $this->conf = $GLOBALS['conf']; 
    if (isset(new dbinfo)) 
     $this->dbi = new dbinfo; 

    $this->modOpt = new modOptions; 
    $this->lang = new language; 

    /** Connect DB extended Class **/ 
    parent::__construct($GLOBALS['connect']); 
} 

BU처럼 DBINFO 클래스 내 구조 기능에 체크를 추가하려면 이 방법을 if isset와 함께 사용할 수 없다면 올바른 방법으로 파일에 클래스가 존재하는지 확인하는 방법을 보여주십시오. 감사

+0

http://php.net/manual/en/function.get-declared-classes.php? –

+2

PHP가 실제로'class_exists()'라는 함수를 가지고 있다는 사실에 아이러닉 한 것이 있습니까? http://php.net/manual/en/function.class-exists.php ... 나는 당신이 방금 에 질문 제목을 타이핑했다면이 답을 얻었고 자신을 톤 질문을 쓰는 시간. – CD001

+0

중복 : http://stackoverflow.com/questions/29940289/check-if-a-class-exist-in-a-file –

답변

1

dbinfo 클래스를 찾고, 귀하의 경우에는, 사용 class_exists()http://php.net/manual/en/function.class-exists.php

을 시도하십시오 : 당신의 클래스는 네임 스페이스가

 if(class_exists('dbinfo')){ 
      //do something 

경우, FUL 네임 스페이스가 클래스 명을 포함한다. 기능이 너무 시도 클래스를로드하는 경우는

관련 문제