<?php
class Person{
private static $count=0;
private $name;
function __construct($name)
{
$this->name = $name;
self::$count =self::$count+1;
}
function enter(){
echo "<h1>Enter".$this->name.self::$count."</h1>";
}
static function getCount(){
return self::$count;
}
}
$p1 = new Person('d');
$p1->enter();
$p2 = new Person('m');
$p2->enter();
$p3 = new Person('j');
$p3->enter();
$p4 = new Person('s');
$p4->enter();
echo Person::getCount();
?>
static 정적인
dynamic 동적인
instance가 생성될 때는 자동으로 동적으로 만들어짐
하지만 static이 붙으면 class에 소속되는 것.
static : class 소속 (class property. static property) - 모든 instance가 공유 가능. 클래스가 직접 호출 가능.
dynamic : instance 소속 멤버 제작.
$this -> 인스턴스에 대한 자기자신
self:: 클래스에 대한 자기자신
'오늘은 공부 중 > PHP' 카테고리의 다른 글
[php] 콘솔 디버깅 / echo (0) | 2021.08.16 |
---|---|
[PHP] 동일값 숫자로 연관배열 - array_count_values() (0) | 2021.08.05 |
[PHP] foreach문 (0) | 2021.08.03 |
[PHP] require, include의 차이 (0) | 2021.07.21 |
오늘의 PHP 공부 with 생활코딩 (0) | 2021.07.13 |