슈

[클래스] Overloading 오버로딩2

· 2014-09-18 (목) 21:12:18 · 911

class Overload {

public function __call($method, $arg) {

if($method == 'test') {

if (is_object($arg[0])) {

$this->testObject($arg[0]);

} else if (is_array($arg[0])) {

$this->testArray($arg[0]);

} else {

$this->testScalar($arg[0]);

}

}

}

 

function testObject($arg) {

echo $arg->test().'<br />';

}

function testArray($arg) {

echo implode(',',$arg).'<br />';

}

function testScalar($arg) {

echo $arg.'<br />';

}

}

 

$ov = new Overload;

$ov->test(new A());

$ov->test(array(1,2,3));

$ov->test('cat');

 

class A {

function test() {

return 'object';

}

} 

|
댓글을 작성하시려면 로그인이 필요합니다.

팁게시판

6,077건

디자인과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
16-03-02 조회 876
16-01-19 조회 507
15-12-23 조회 659
15-12-08 조회 1,309
14-10-30 조회 2,897
14-06-06 조회 2,311
12-08-30 조회 1,522
12-08-20 조회 1,288
12-07-15 조회 2,720
12-07-13 조회 1,495
12-07-06 조회 1,481
12-06-27 조회 1,032
12-06-23 조회 1,149
12-05-03 조회 3,113
12-04-20 조회 2,057
12-03-29 조회 2,378
12-03-22 조회 2,725
12-03-22 조회 1,470
12-03-21 조회 1,299
12-03-11 조회 1,637
12-03-06 조회 1,914
12-02-22 조회 2,256
12-02-17 조회 1,237
12-02-17 조회 4,282
12-02-14 조회 3,904