File: pear_autoloader.phpt

package info (click to toggle)
php-pear 1%3A1.10.1%2Bsubmodules%2Bnotgz-9%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,600 kB
  • sloc: php: 51,665; ansic: 38,629; xml: 32,572; yacc: 677; pascal: 452; makefile: 122; sh: 116
file content (81 lines) | stat: -rw-r--r-- 1,678 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--TEST--
PEAR_Autoloader
--SKIPIF--
skip
<?php /*if (!extension_loaded("overload")) die("skip\n"); */ ?>
--FILE--
<?php

include dirname(__FILE__)."/../PEAR/Autoloader.php";

class test1 extends PEAR_Autoloader {
    function __construct() {
	$this->addAutoload(array(
	    'testfunc1' => 'testclass1',
	    'testfunca' => 'testclass1',
	    'testfunc2' => 'testclass2',
	    'testfuncb' => 'testclass2',
	));
    }
}

class testclass1 {
    function testfunc1($a) {
	print "testfunc1 arg=";var_dump($a);
	return 1;
    }
    function testfunca($a) {
	print "testfunca arg=";var_dump($a);
	return 2;
    }
}

class testclass2 {
    function testfunc2($b) {
	print "testfunc2 arg=";var_dump($b);
	return 3;
    }
    function testfuncb($b) {
	print "testfuncb arg=";var_dump($b);
	return 4;
    }
}

function dump($obj) {
    print "mapped methods:";
    foreach ($obj->_method_map as $method => $object) {
	print " $method";
    }
    print "\n";
}

function call($msg, $retval) {
    print "calling $msg returned $retval\n";
}

$obj = new test1;
dump($obj);
call("testfunc1", $obj->testfunc1(2));
dump($obj);
call("testfunca", $obj->testfunca(2));
dump($obj);
call("testfunc2", $obj->testfunc2(2));
dump($obj);
call("testfuncb", $obj->testfuncb(2));
dump($obj);

?>
--EXPECT--
mapped methods:
testfunc1 arg=int(2)
calling testfunc1 returned 1
mapped methods: testfunc1 testfunca
testfunca arg=int(2)
calling testfunca returned 2
mapped methods: testfunc1 testfunca
testfunc2 arg=int(2)
calling testfunc2 returned 3
mapped methods: testfunc1 testfunca testfunc2 testfuncb
testfuncb arg=int(2)
calling testfuncb returned 4
mapped methods: testfunc1 testfunca testfunc2 testfuncb