[php] 간단 Properties class test 5.0 이상에서 > 팁앤테크

본문 바로가기
사이트 내 전체검색

팁앤테크

[php] 간단 Properties class test 5.0 이상에서

페이지 정보

본문

<?
/********************

* Properties class
*
* Date : 2010.
*
* @author
*
* desc :
* map 자료구조 형태의 프로퍼티를 관리하는 class
*
*/


class Properties
{
private $list = null; // 프로퍼티를 담을 배열

/*******************
* 생성자
* arg[0] : 타입 - Properties class type 이어야 한다. */
public function __construct(Properties $defaultProperties=null)
{
if ($defaultProperties)
{
$this->list = $defaultProperties->getList();
}
}


/*******************
* property 값을 리턴한다.
* arg[0] : list의 key */
public function getProperty($key)
{
if (is_array($this->list) && $key)
return $this->list[$key];
else
return "";
}


/*******************
* property 값을 리턴한다.
* arg[0] : list의 key */
public function setProperty($key, $value)
{
$this->list[$key] = $value;
}


/*******************
* property 값을 배열형태로 받는다.
* arg[0] : property 배열 */
public function setList($list)
{
$this->list = $list;
}


/*******************
* property 배열을 리턴한다.
* */
public function getList()
{
return $this->list;
}
}


/*
$p = new Properties();
$p->setProperty('apple', '사과');

$props = new Properties($p);
echo $props->getProperty('apple')."<br/>";
var_dump($props->getList());


result:
>> 사과
>> array(1) { ["apple"]=> string(6) "사과" }
*/


class Item
{
public $name = "";
public $price = 0;
protected $spec = null;

public function __construct($name, $price)
{
$this->name = $name;
$this->price = $price;
}

public function getSpec()
{
return $this->spec;
}

public function setSpec( Properties $props )
{
$this->spec= $props;
//echo get_class($this->props);
}

}



$p = new Properties();
$p->setProperty('width', '400');
$p->setProperty('height', '700');
$p->setProperty('forecolor', 'silver');
$p->setProperty('backcolor', 'black');

$item = new Item('iphone', 300000);
$item->setSpec($p);

echo $item->getSpec()->getProperty('forecolor');
/*
result:
>> silver
*/
?>
추천0

댓글목록

등록된 댓글이 없습니다.

Total 825건 11 페이지
  • RSS
팁앤테크 목록
번호 제목 글쓴이 조회 추천 날짜
575 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 14393 0 04-11
574 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 22418 0 03-14
573 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 23863 0 02-13
572 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 26602 0 02-09
571 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 19623 0 02-08
570 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 19297 0 02-08
569 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 19892 0 01-31
568 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 23882 0 01-28
567 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 34979 0 01-27
566 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 25190 0 01-26
565 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 25576 0 01-24
564 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 16677 0 01-24
563 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 17384 0 01-24
562 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 20912 0 01-24
561 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 20528 0 01-24
560 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 26285 0 01-23
559 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 26214 0 01-15
558 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 26659 0 01-15
557 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 27564 0 01-10
556 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 13149 0 01-04
555 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15232 0 12-27
554 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 29621 0 12-14
553 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 28738 0 12-10
552 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 32679 0 12-08
551 제로쪽지보내기 홈페이지 자기소개 아이디로 검색 전체게시물 36958 0 11-17

검색

회원로그인

회원가입

사이트 정보

株式会社YHPLUS / 대표 : ZERO
〒140-0011 東京都品川区東大井2-5-9-203
050-5539-7787
오픈카카오톡 (YHPLUS) :
https://open.kakao.com/o/slfDj15d

접속자집계

오늘
4,072
어제
8,087
최대
8,087
전체
1,418,710
Copyright (c) 株式会社YHPLUS. All rights reserved.