ch09 / exam09-04.php

생성자(__construct)와 소멸자(__destruct) 생명주기 시각화

객체 생성 시 생성자 실행, 스크립트 종료 시(메모리 해제 시) 소멸자 자동 호출

PHP Source (ch09/exam09-04.php)
단계: 0 / 0
1<?php
3class MyClass {
4function __construct() { print "생성자 실행<br>"; }
8function __destruct() { print "소멸자 실행<br>"; }
11}
13$obj = new MyClass();
15?>
준비 완료 실행 버튼 또는 다음 단계를 눌러주세요.
객체 생명주기 (Object Lifecycle)
객체 상태: 대기
new MyClass() 대기 중
http://localhost/ch09/exam09-04.php

소멸자(__destruct)의 역할