프로그램
php 에서 var 키워드의 사용.
(주)CKBcorp.,
2012. 5. 21. 13:15
반응형
php 에서는 변수를 선언할 때 형을 지정하지 않는다.
헌데, php 코드 보면 변수 선언에 var 키워드가 사용될 때가 있다.
<?php
class Cart {
var $items; // Items in our shopping cart
// Add $num articles of $artnr to the cart
function add_item($artnr, $num) {
$this->items[$artnr] += $num;
}
// Take $num articles of $artnr out of the cart
function remove_item($artnr, $num) {
if ($this->items[$artnr] > $num) {
$this->items[$artnr] -= $num;
return true;
} elseif ($this->items[$artnr] == $num) {
unset($this->items[$artnr]);
return true;
} else {
return false;
}
}
}
?>
결론부터 말하면, var 키워드는 class 의 member 변수 선언할 때 쓰인다.
괜히 찜찜해서 찾아봤다.
반응형