Annotation of embedaddon/php/ext/spl/tests/spl_autoload_008.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: SPL: spl_autoload() with exceptions
! 3: --INI--
! 4: include_path=.
! 5: --FILE--
! 6: <?php
! 7:
! 8: function MyAutoLoad($className)
! 9: {
! 10: echo __METHOD__ . "($className)\n";
! 11: throw new Exception('Bla');
! 12: }
! 13:
! 14: class MyAutoLoader
! 15: {
! 16: static function autoLoad($className)
! 17: {
! 18: echo __METHOD__ . "($className)\n";
! 19: throw new Exception('Bla');
! 20: }
! 21:
! 22: function dynaLoad($className)
! 23: {
! 24: echo __METHOD__ . "($className)\n";
! 25: throw new Exception('Bla');
! 26: }
! 27: }
! 28:
! 29: $obj = new MyAutoLoader;
! 30:
! 31: $funcs = array(
! 32: 'MyAutoLoad',
! 33: 'MyAutoLoader::autoLoad',
! 34: 'MyAutoLoader::dynaLoad',
! 35: array('MyAutoLoader', 'autoLoad'),
! 36: array('MyAutoLoader', 'dynaLoad'),
! 37: array($obj, 'autoLoad'),
! 38: array($obj, 'dynaLoad'),
! 39: );
! 40:
! 41: foreach($funcs as $idx => $func)
! 42: {
! 43: echo "====$idx====\n";
! 44:
! 45: try
! 46: {
! 47: var_dump($func);
! 48: spl_autoload_register($func);
! 49: if (count(spl_autoload_functions()))
! 50: {
! 51: echo "registered\n";
! 52:
! 53: var_dump(class_exists("NoExistingTestClass", true));
! 54: }
! 55: }
! 56: catch (Exception $e)
! 57: {
! 58: echo get_class($e) . ": " . $e->getMessage() . "\n";
! 59: }
! 60:
! 61: spl_autoload_unregister($func);
! 62: var_dump(count(spl_autoload_functions()));
! 63: }
! 64:
! 65: ?>
! 66: ===DONE===
! 67: <?php exit(0); ?>
! 68: --EXPECTF--
! 69: ====0====
! 70: string(10) "MyAutoLoad"
! 71: registered
! 72: MyAutoLoad(NoExistingTestClass)
! 73: Exception: Bla
! 74: int(0)
! 75: ====1====
! 76: string(22) "MyAutoLoader::autoLoad"
! 77: registered
! 78: MyAutoLoader::autoLoad(NoExistingTestClass)
! 79: Exception: Bla
! 80: int(0)
! 81: ====2====
! 82: string(22) "MyAutoLoader::dynaLoad"
! 83: LogicException: Function 'MyAutoLoader::dynaLoad' not callable (non-static method MyAutoLoader::dynaLoad() should not be called statically)
! 84: int(0)
! 85: ====3====
! 86: array(2) {
! 87: [0]=>
! 88: string(12) "MyAutoLoader"
! 89: [1]=>
! 90: string(8) "autoLoad"
! 91: }
! 92: registered
! 93: MyAutoLoader::autoLoad(NoExistingTestClass)
! 94: Exception: Bla
! 95: int(0)
! 96: ====4====
! 97: array(2) {
! 98: [0]=>
! 99: string(12) "MyAutoLoader"
! 100: [1]=>
! 101: string(8) "dynaLoad"
! 102: }
! 103: LogicException: Passed array specifies a non static method but no object (non-static method MyAutoLoader::dynaLoad() should not be called statically)
! 104: int(0)
! 105: ====5====
! 106: array(2) {
! 107: [0]=>
! 108: object(MyAutoLoader)#%d (0) {
! 109: }
! 110: [1]=>
! 111: string(8) "autoLoad"
! 112: }
! 113: registered
! 114: MyAutoLoader::autoLoad(NoExistingTestClass)
! 115: Exception: Bla
! 116: int(0)
! 117: ====6====
! 118: array(2) {
! 119: [0]=>
! 120: object(MyAutoLoader)#%d (0) {
! 121: }
! 122: [1]=>
! 123: string(8) "dynaLoad"
! 124: }
! 125: registered
! 126: MyAutoLoader::dynaLoad(NoExistingTestClass)
! 127: Exception: Bla
! 128: int(0)
! 129: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>