슈

[클래스] Overloading 오버로딩2

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

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,255
14-09-21 조회 3,743
14-09-20 조회 3,745
14-09-20 조회 3,653
14-09-20 조회 3,836
14-09-19 조회 3,787
14-09-19 조회 3,928
14-09-19 조회 3,819
14-09-19 조회 3,837
14-09-19 조회 3,751
14-09-19 조회 4,039
14-09-19 조회 3,797
14-09-19 조회 3,842
14-09-19 조회 3,808
14-09-18 조회 3,884
14-09-18 조회 3,850
14-09-18 조회 4,123
14-09-18 조회 4,085
14-09-18 조회 4,099
14-09-18 조회 4,808