생성자 : 인스턴스 생성 시 수행할 기본 작업을 정의한 메서드.
<?php // 클래스 class MyFileObject{ function __construct($fname){ $this->filename = $fname; } function isFile(){ return is_file($this->filename); } } // 인스턴스 $file = new MyFileObject('data.txt'); // $file->filename = 'data.txt'; var_dump($file->isFile()); var_dump($file->filename); https://www.php.net/manual/en/language.oop5.decon.php
<?php
// 클래스
class MyFileObject{
function __construct($fname){
$this->filename = $fname;
}
function isFile(){
return is_file($this->filename);
// 인스턴스
$file = new MyFileObject('data.txt');
// $file->filename = 'data.txt';
var_dump($file->isFile());
var_dump($file->filename);
https://www.php.net/manual/en/language.oop5.decon.php
https://opentutorials.org/module/6/15729
PS.
Constructor (생성자) : __construct()함수 https://homzzang.com/b/php-1063
Constructor (생성자) : __construct()함수
https://homzzang.com/b/php-1063