PHP 변수 및 유형 확장의 반영 및 사용
1. 개요 및 설치
PHP 5에는 리버스 엔지니어링 클래스, 인터페이스, 기능, 메소드 및 확장 기능이 추가된 완전한 리플렉션 API가 있습니다. 또한 Reflection API는 함수, 클래스 및 메서드에서 문서 주석을 추출하는 메서드를 제공합니다.
일부 내부 API에는 리플렉션 확장이 작동하는 데 필요한 코드가 누락되어 있습니다. 예를 들어, 내장된 PHP 클래스에는 반영된 속성에 대한 데이터가 누락될 수 있습니다. 그러나 이러한 드문 경우는 버그로 간주되므로 발견하고 수정해야 합니다.
이러한 기능은 PHP 코어의 일부이므로 설치가 필요하지 않습니다.
2. 사용 예
리플렉션 문서에는 일반적으로 각 클래스의 __construct 문서에 많은 예가 있습니다.
예제 Shell에서의 반영 예(터미널)
$ php --rf strlen
$ php --rc finfo
$ php --re json
$ php --ri dom
위 루틴의 출력은 다음과 유사합니다.
Function [ <internal:Core> function strlen ] { - Parameters [1] { Parameter #0 [ <required> $str ] } } Class [ <internal:fileinfo> class finfo ] { - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [4] { Method [ <internal:fileinfo, ctor> public method finfo ] { - Parameters [2] { Parameter #0 [ <optional> $options ] Parameter #1 [ <optional> $arg ] } } Method [ <internal:fileinfo> public method set_flags ] { - Parameters [1] { Parameter #0 [ <required> $options ] } } Method [ <internal:fileinfo> public method file ] { - Parameters [3] { Parameter #0 [ <required> $filename ] Parameter #1 [ <optional> $options ] Parameter #2 [ <optional> $context ] } } Method [ <internal:fileinfo> public method buffer ] { - Parameters [3] { Parameter #0 [ <required> $string ] Parameter #1 [ <optional> $options ] Parameter #2 [ <optional> $context ] } } } } Extension [ <persistent> extension #23 json version 1.2.1 ] { - Constants [10] { Constant [ integer JSON_HEX_TAG ] { 1 } Constant [ integer JSON_HEX_AMP ] { 2 } Constant [ integer JSON_HEX_APOS ] { 4 } Constant [ integer JSON_HEX_QUOT ] { 8 } Constant [ integer JSON_FORCE_OBJECT ] { 16 } Constant [ integer JSON_ERROR_NONE ] { 0 } Constant [ integer JSON_ERROR_DEPTH ] { 1 } Constant [ integer JSON_ERROR_STATE_MISMATCH ] { 2 } Constant [ integer JSON_ERROR_CTRL_CHAR ] { 3 } Constant [ integer JSON_ERROR_SYNTAX ] { 4 } } - Functions { Function [ <internal:json> function json_encode ] { - Parameters [2] { Parameter #0 [ <required> $value ] Parameter #1 [ <optional> $options ] } } Function [ <internal:json> function json_decode ] { - Parameters [3] { Parameter #0 [ <required> $json ] Parameter #1 [ <optional> $assoc ] Parameter #2 [ <optional> $depth ] } } Function [ <internal:json> function json_last_error ] { - Parameters [0] { } } } } dom DOM/XML => enabled DOM/XML API Version => 20031129 libxml Version => 2.7.3 HTML Support => enabled XPath Support => enabled XPointer Support => enabled Schema Support => enabled RelaxNG Support => enabled
3. 관련 확장
빌드를 생성하려는 경우 클래스 특수 버전(예: 메서드를 쉽게 액세스할 수 있는 멤버 변수로 바꾸거나 강조 표시된 HTML을 만들고 내보낼 때 유틸리티 메서드 사용)을 계속하고 확장할 수 있습니다.
예제 #1 내장 클래스 확장
<?php /** * My Reflection_Method class */ class My_Reflection_Method extends ReflectionMethod { public $visibility = array(); public function __construct($o, $m) { parent::__construct($o, $m); $this->visibility = Reflection::getModifierNames($this->getModifiers()); } } /** * Demo class #1 * */ class T { protected function x() {} } /** * Demo class #2 * */ class U extends T { function x() {} } // 输出信息 var_dump(new My_Reflection_Method('U', 'x')); ?> 以上例程的输出类似于: object(My_Reflection_Method)#1 (3) { ["visibility"]=> array(1) { [0]=> string(6) "public" } ["name"]=> string(1) "x" ["class"]=> string(1) "U" }
생성자를 재정의하는 경우 삽입된 코드를 작성하기 전에 상위 클래스의 생성자를 호출해야 합니다. 그렇지 않으면 다음과 같은 결과가 발생합니다: 치명적인 오류: 내부 오류: 반사 객체 검색 실패
4. 반사 클래스
반사 — 반사 클래스
ReflectionClass — ReflectionClass 클래스
ReflectionZendExtension — ReflectionZendExtension 클래스
ReflectionExtension — ReflectionExtension 클래스
ReflectionFunction — ReflectionFunction 클래스
ReflectionFunctionAbstract — ionFunction 추상클래스
ReflectionMethod — ReflectionMethod 클래스
ReflectionObject — ReflectionObject 클래스
ReflectionParameter — ReflectionParameter 클래스
ReflectionProperty — ReflectionProperty 클래스
Reflector — Reflector 인터페이스
ReflectionException — ReflectionException 클래스

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

CakePHP는 PHP용 오픈 소스 프레임워크입니다. 이는 애플리케이션을 훨씬 쉽게 개발, 배포 및 유지 관리할 수 있도록 하기 위한 것입니다. CakePHP는 강력하고 이해하기 쉬운 MVC와 유사한 아키텍처를 기반으로 합니다. 모델, 뷰 및 컨트롤러 gu

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는

CakePHP는 오픈 소스 MVC 프레임워크입니다. 이를 통해 애플리케이션 개발, 배포 및 유지 관리가 훨씬 쉬워집니다. CakePHP에는 가장 일반적인 작업의 과부하를 줄이기 위한 여러 라이브러리가 있습니다.

이 튜토리얼은 PHP를 사용하여 XML 문서를 효율적으로 처리하는 방법을 보여줍니다. XML (Extensible Markup Language)은 인간의 가독성과 기계 구문 분석을 위해 설계된 다목적 텍스트 기반 마크 업 언어입니다. 일반적으로 데이터 저장 AN에 사용됩니다
