위치 : 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개
게시글 목록
| 번호 | 제목 |
|---|---|
| 6615 | |
| 6614 | |
| 6606 | |
| 19438 |
JavaScript
audio 음악이 끝났을때 이벤트를 넣을 수 있나요?
1
|
| 6604 | |
| 6592 | |
| 6588 | |
| 6586 | |
| 6583 | |
| 6577 | |
| 19437 |
JavaScript
캔버스 ( html5 ) 그림 그리기3
|
| 6576 | |
| 6575 | |
| 6574 | |
| 19435 | |
| 27715 | |
| 6571 | |
| 6570 | |
| 6562 | |
| 6559 | |
| 6553 | |
| 6552 | |
| 6551 | |
| 6548 | |
| 24572 | |
| 6545 | |
| 6544 | |
| 6543 | |
| 6541 | |
| 6539 | |
| 6527 | |
| 6526 | |
| 6524 | |
| 6519 | |
| 6516 | |
| 27701 | |
| 27699 | |
| 6515 | |
| 19434 |
JavaScript
캔버스 ( html5 ) 그림 그리기2
|
| 6514 | |
| 19433 |
JavaScript
캔버스 ( html5 ) 그림 그리기
|
| 6503 | |
| 19432 |
jQuery
파일 첨부시심플하게 버튼으로만 되게..
|
| 6500 | |
| 6497 | |
| 6496 | |
| 6491 | |
| 6485 | |
| 32041 | |
| 6483 | |
| 6479 | |
| 6478 | |
| 6475 | |
| 6473 | |
| 6467 | |
| 6465 | |
| 6462 | |
| 27697 | |
| 6454 | |
| 6451 | |
| 27695 | |
| 6446 | |
| 6440 | |
| 6437 | |
| 27688 | |
| 6433 | |
| 6430 | |
| 6427 | |
| 6426 | |
| 6422 | |
| 6421 | |
| 6418 | |
| 27686 | |
| 27678 | |
| 6414 | |
| 6410 | |
| 6404 | |
| 6400 | |
| 6398 | |
| 6389 | |
| 6384 | |
| 6383 | |
| 6378 | |
| 6370 | |
| 6363 | |
| 6348 | |
| 6338 | |
| 6329 | |
| 6328 | |
| 6316 | |
| 6309 | |
| 6299 | |
| 6296 | |
| 27674 | |
| 27671 | |
| 6293 | |
| 6282 | |
| 24570 | |
| 6277 | |
| 6264 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기