trait_exists — 형질이 존재하는지 검사한다. > 개발자팁

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

trait_exists — 형질이 존재하는지 검사한다. 정보

PHP trait_exists — 형질이 존재하는지 검사한다.

본문

trait_exists —  형질이 존재하는지 검사한다.

 

설명 :

bool trait_exists ( string $traitname [, bool $autoload ] )

 

인수 :

traitname

확인할 특성의 이름

 

autoload

이미로드되지 않은 경우 자동로드할지 여부입니다.

 

반환값 :

특성이 존재하면 TRUE를 반환하고 그렇지 않으면 FALSE를 반환하고, 오류가 발생하면 NULL을 반환합니다.

 

<?php

trait World {

 

    private static $instance;

    protected $tmp;

 

    public static function World()

    {

        self::$instance = new static();

        self::$instance->tmp = get_called_class().' '.__TRAIT__;

        

        return self::$instance;

    }

 

}

 

if ( trait_exists( 'World' ) ) {

    

    class Hello {

        use World;

 

        public function text( $str )

        {

            return $this->tmp.$str;

        }

    }

 

}

 

echo Hello::World()->text('!!!'); // Hello World!!!

추천
1
  • 복사

댓글 0개

© SIRSOFT
현재 페이지 제일 처음으로