위치 : http://kr1.php.net/manual/en/function.call-user-func-array.php
<?php
Class Delegate
{
private $arrInstances = array();
protected function addObject( $oElement )
{
// add one element on the end of the stack //
$this->arrInstances[] = $oElement;
}
public function __call( $strMethod, $arrParams )
{
// for each element in instance //
foreach( $this->arrInstances as $oElement )
{
// get the class of the element //
$strClass = get_class( $oElement );
// get all methods of the class //
$arrMethods = get_class_methods( $strClass );
// case the method exists into this class //
if( in_array( $strMethod , $arrMethods ) )
{
// prepare caller //
$arrCaller = Array( $strClass , $strMethod );
// return the result of the method into the object //
return call_user_func_array( $arrCaller, $arrParams );
}
}
// any object has the method //
// throw a exception //
throw new Exception( " Method " . $strMethod . " not exist in this class " . get_class($this ) . "." );
}
}
class Log
{
public function sayHi()
{
print "hi!" . "<br/>\n";
}
public function sayMyName()
{
print "log" . "<br/>\n";
}
}
class Other
{
public function sayHello()
{
print "hello there!" . "<br/>\n";
}
public function sayMyName()
{
print "other" . "<br/>\n";
}
}
class Example extends Delegate
{
public function __construct()
{
$this->addObject( new Log() );
$this->addObject( new Other() );
}
}
$oExample = new Example();
$oExample->sayHi();
$oExample->sayHello();
$oExample->sayMyName();
/*
hi!<br/>
hello there!<br/>
log<br/>
*/
?>
댓글 6개
게시글 목록
| 번호 | 제목 |
|---|---|
| 6256 | |
| 6255 | |
| 6254 | |
| 19430 | |
| 6253 | |
| 6252 | |
| 27670 | |
| 6249 | |
| 6246 | |
| 6242 | |
| 6241 | |
| 19429 |
JavaScript
자바스크립트로 이미지 롤링 관련 문의드립니다.
|
| 6238 | |
| 6237 | |
| 19426 | |
| 19413 | |
| 19411 | |
| 6232 | |
| 6227 | |
| 6226 | |
| 6224 | |
| 19408 | |
| 6223 | |
| 6221 | |
| 6220 | |
| 27663 | |
| 6213 | |
| 6212 | |
| 27661 | |
| 27659 | |
| 6209 | |
| 6203 | |
| 6200 | |
| 27654 | |
| 6194 | |
| 6188 | |
| 6180 | |
| 6173 | |
| 6150 | |
| 19407 | |
| 6145 | |
| 6141 | |
| 6138 | |
| 6131 | |
| 27650 | |
| 6128 | |
| 6125 | |
| 6122 | |
| 27648 | |
| 6119 | |
| 6114 | |
| 6109 | |
| 19402 |
JavaScript
위지윅 에디터 만들때 선택영역 풀리는 문제
4
|
| 6108 | |
| 27647 | |
| 6106 | |
| 27642 | |
| 27637 | |
| 6105 | |
| 6101 | |
| 6095 | |
| 6093 | |
| 6091 | |
| 6088 | |
| 27635 | |
| 27634 | |
| 6087 | |
| 27628 | |
| 6083 | |
| 6077 | |
| 24562 | |
| 27614 | |
| 6072 | |
| 6067 | |
| 6065 | |
| 19400 | |
| 19399 |
기타
IE 구분하기
|
| 19398 |
기타
js, css 캐싱 팁
|
| 19397 | |
| 6062 | |
| 27608 | |
| 6057 | |
| 27606 | |
| 19396 |
JavaScript
롤링 배너 이해하는데 도움이 될것 같아 올립니다
|
| 6054 | |
| 27600 | |
| 6048 | |
| 6040 | |
| 6031 | |
| 6028 | |
| 6024 | |
| 27594 | |
| 27593 | |
| 6023 | |
| 6018 | |
| 19395 | |
| 19394 |
PHP
게시판 페이지 관련 글입니다.
|
| 19390 | |
| 19388 |
JavaScript
멀티 체크박스입니다.
1
|
| 19386 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기