테스트 사이트 - 개발 중인 베타 버전입니다

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!!!

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

게시판 목록

개발자팁

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