Annotation of embedaddon/php/ext/reflection/tests/007.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: ReflectionClass::newInstance[Args]
        !             3: --FILE--
        !             4: <?php
        !             5: 
        !             6: function test($class)
        !             7: {
        !             8:        echo "====>$class\n";
        !             9:        try
        !            10:        {
        !            11:                $ref = new ReflectionClass($class);
        !            12:        }
        !            13:        catch (ReflectionException $e)
        !            14:        {
        !            15:                var_dump($e->getMessage());
        !            16:                return; // only here
        !            17:        }
        !            18: 
        !            19:        echo "====>newInstance()\n";
        !            20:        try
        !            21:        {
        !            22:                var_dump($ref->newInstance());
        !            23:        }
        !            24:        catch (ReflectionException $e)
        !            25:        {
        !            26:                var_dump($e->getMessage());
        !            27:        }
        !            28:        
        !            29:        echo "====>newInstance(25)\n";
        !            30:        try
        !            31:        {
        !            32:                var_dump($ref->newInstance(25));
        !            33:        }
        !            34:        catch (ReflectionException $e)
        !            35:        {
        !            36:                var_dump($e->getMessage());
        !            37:        }
        !            38: 
        !            39:        echo "====>newInstance(25, 42)\n";
        !            40:        try
        !            41:        {
        !            42:                var_dump($ref->newInstance(25, 42));
        !            43:        }
        !            44:        catch (ReflectionException $e)
        !            45:        {
        !            46:                var_dump($e->getMessage());
        !            47:        }
        !            48:        
        !            49:        echo "\n";
        !            50: }
        !            51: 
        !            52: function __autoload($class)
        !            53: {
        !            54:        echo __FUNCTION__ . "($class)\n";
        !            55: }
        !            56: 
        !            57: test('Class_does_not_exist');
        !            58: 
        !            59: Class NoCtor
        !            60: {
        !            61: }
        !            62: 
        !            63: test('NoCtor');
        !            64: 
        !            65: Class WithCtor
        !            66: {
        !            67:        function __construct()
        !            68:        {
        !            69:                echo __METHOD__ . "()\n";
        !            70:                var_dump(func_get_args());
        !            71:        }
        !            72: }
        !            73: 
        !            74: test('WithCtor');
        !            75: 
        !            76: Class WithCtorWithArgs
        !            77: {
        !            78:        function __construct($arg)
        !            79:        {
        !            80:                echo __METHOD__ . "($arg)\n";
        !            81:                var_dump(func_get_args());
        !            82:        }
        !            83: }
        !            84: 
        !            85: test('WithCtorWithArgs');
        !            86: 
        !            87: ?>
        !            88: ===DONE===
        !            89: <?php exit(0); ?>
        !            90: --EXPECTF--
        !            91: 
        !            92: ====>Class_does_not_exist
        !            93: __autoload(Class_does_not_exist)
        !            94: string(41) "Class Class_does_not_exist does not exist"
        !            95: ====>NoCtor
        !            96: ====>newInstance()
        !            97: object(NoCtor)#%d (0) {
        !            98: }
        !            99: ====>newInstance(25)
        !           100: string(86) "Class NoCtor does not have a constructor, so you cannot pass any constructor arguments"
        !           101: ====>newInstance(25, 42)
        !           102: string(86) "Class NoCtor does not have a constructor, so you cannot pass any constructor arguments"
        !           103: 
        !           104: ====>WithCtor
        !           105: ====>newInstance()
        !           106: WithCtor::__construct()
        !           107: array(0) {
        !           108: }
        !           109: object(WithCtor)#%d (0) {
        !           110: }
        !           111: ====>newInstance(25)
        !           112: WithCtor::__construct()
        !           113: array(1) {
        !           114:   [0]=>
        !           115:   int(25)
        !           116: }
        !           117: object(WithCtor)#%d (0) {
        !           118: }
        !           119: ====>newInstance(25, 42)
        !           120: WithCtor::__construct()
        !           121: array(2) {
        !           122:   [0]=>
        !           123:   int(25)
        !           124:   [1]=>
        !           125:   int(42)
        !           126: }
        !           127: object(WithCtor)#%d (0) {
        !           128: }
        !           129: 
        !           130: ====>WithCtorWithArgs
        !           131: ====>newInstance()
        !           132: 
        !           133: Warning: Missing argument 1 for WithCtorWithArgs::__construct() in %s007.php on line %d
        !           134: 
        !           135: Notice: Undefined variable: arg in %s007.php on line %d
        !           136: WithCtorWithArgs::__construct()
        !           137: array(0) {
        !           138: }
        !           139: object(WithCtorWithArgs)#%d (0) {
        !           140: }
        !           141: ====>newInstance(25)
        !           142: WithCtorWithArgs::__construct(25)
        !           143: array(1) {
        !           144:   [0]=>
        !           145:   int(25)
        !           146: }
        !           147: object(WithCtorWithArgs)#%d (0) {
        !           148: }
        !           149: ====>newInstance(25, 42)
        !           150: WithCtorWithArgs::__construct(25)
        !           151: array(2) {
        !           152:   [0]=>
        !           153:   int(25)
        !           154:   [1]=>
        !           155:   int(42)
        !           156: }
        !           157: object(WithCtorWithArgs)#%d (0) {
        !           158: }
        !           159: 
        !           160: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>