• 회원가입
  • 로그인
  • 구글아이디로 로그인

[PHP-생코] PHP 4강 - 클래스・인스턴스(객체)・메서드 생성 ★★★

1,465  

[인스턴스 기호] ->

$this->변수명 : 인스턴스 용 변수.

$인스턴스명->메서드명() : 인스턴스 용 메서드 출력 코드.

 

[클래스 전용 기호] ::  (9강에서 배울 내용)

static 키워드 추가해 「$변수명・메서드」 정의 후, 

self::$변수명 : 클래스 용 변수.

클래스명::메서드명() : 클래스 용 메서드 출력 코드.

 

 

<?php

// 클래스 생성

class MyFileObject{

  function isFile(){

    return is_file('data.txt');

  }

}

 

// 인스턴스1 생성

$file = new MyFileObject();

var_dump($file->isFile());

 

// 인스턴스2 생성 

$file2 = new MyFileObject();

var_dump($file2->isFile());

?>

 

https://opentutorials.org/module/6/15726

https://www.php.net/manual/en/language.oop5.basic.php


분류 제목
게시물이 없습니다.
목록
찾아주셔서 감사합니다. Since 2012