슈

[클래스] Overloading 오버로딩2

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

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';

}

} 

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

프로그램

8,188건
+
제목 글쓴이 날짜 조회
14-09-21 조회 4,245
14-09-21 조회 3,732
14-09-20 조회 3,740
14-09-20 조회 3,642
14-09-20 조회 3,827
14-09-19 조회 3,779
14-09-19 조회 3,913
14-09-19 조회 3,807
14-09-19 조회 3,831
14-09-19 조회 3,744
14-09-19 조회 4,029
14-09-19 조회 3,783
14-09-19 조회 3,831
14-09-19 조회 3,799
14-09-18 조회 3,876
14-09-18 조회 3,836
14-09-18 조회 4,113
14-09-18 조회 4,079
14-09-18 조회 4,090
14-09-18 조회 4,794