라이브러리

[PHP] ReflectionClass::newLazyGhost - 새로운 레이지 고스트 인스턴스를 생성합니다.




ReflectionClass::newLazyGhost


`ReflectionClass::newLazyGhost`는 PHP 8.1 버전부터 지원하는 기능입니다. 이 기능은 ReflectionClass를 사용하여 클래스를 인스턴스화 할 때, 클래스가 아직 로드되지 않은 경우에 사용됩니다.

# Lazy Loading


Lazy Loading은 클래스를 로드하는 것을 지연시키는 기술입니다. 클래스가 실제로 사용되기 전에 클래스를 로드하는 대신, 클래스가 사용될 때까지 로드하지 않고, 필요한 클래스를 로드합니다.

# Ghost


Ghost는 PHP 8.1 버전부터 지원하는 기능입니다. Ghost는 클래스를 로드하는 것을 지연시키는 기술입니다. Ghost를 사용하면 클래스를 로드하는 것을 지연시키고, 클래스가 실제로 사용되기 전에 클래스를 로드하지 않습니다.

# newLazyGhost


`newLazyGhost`는 ReflectionClass::newLazyGhost를 사용하여 클래스를 인스턴스화 할 때, 클래스가 아직 로드되지 않은 경우에 사용됩니다. 이 기능은 클래스를 로드하는 것을 지연시키고, 클래스가 실제로 사용되기 전에 클래스를 로드하지 않습니다.

예제


#hostingforum.kr
php

// myclass.php

class MyClass {

    public function __construct() {

        echo "MyClass 생성
";

    }

}



// main.php

require_once 'vendor/autoload.php';



use ReflectionClass;



$reflectionClass = new ReflectionClass('MyClass');

$reflectionClass->newLazyGhost();



// MyClass를 사용하지 않음

$reflectionClass = new ReflectionClass('MyClass');

$reflectionClass->newLazyGhost();



// MyClass를 사용함

$reflectionClass = new ReflectionClass('MyClass');

$obj = $reflectionClass->newInstanceWithoutConstructor();

$obj = $reflectionClass->newLazyGhost()->newInstanceWithoutConstructor();



// MyClass를 사용하지 않음

$reflectionClass = new ReflectionClass('MyClass');

$reflectionClass->newLazyGhost();



// MyClass를 사용함

$reflectionClass = new ReflectionClass('MyClass');

$obj = $reflectionClass->newInstanceWithoutConstructor();

$obj = $reflectionClass->newLazyGhost()->newInstanceWithoutConstructor();



결과


#hostingforum.kr


MyClass 생성

MyClass 생성



결론


`ReflectionClass::newLazyGhost`는 PHP 8.1 버전부터 지원하는 기능입니다. 이 기능은 클래스를 로드하는 것을 지연시키고, 클래스가 실제로 사용되기 전에 클래스를 로드하지 않습니다. 이 기능은 클래스를 로드하는 것을 지연시키는 기술인 Lazy Loading과 Ghost를 사용하여 클래스를 로드하는 것을 지연시키고, 클래스가 실제로 사용되기 전에 클래스를 로드하지 않습니다.

참고


- [PHP 8.1 - ReflectionClass::newLazyGhost](https://www.php.net/manual/en/reflectionclass.newlazyghost.php)
- [Lazy Loading](https://en.wikipedia.org/wiki/Lazy_loading)
- [Ghost](https://en.wikipedia.org/wiki/Ghost_(programming))
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 288 페이지

검색

게시물 검색