Annotation of embedaddon/php/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: ReflectionMethod::isConstructor()
! 3: --FILE--
! 4: <?php
! 5:
! 6: class NewCtor {
! 7: function __construct() {
! 8: echo "In " . __METHOD__ . "\n";
! 9: }
! 10:
! 11: }
! 12: echo "New-style constructor:\n";
! 13: $methodInfo = new ReflectionMethod("NewCtor::__construct");
! 14: var_dump($methodInfo->isConstructor());
! 15:
! 16: class ExtendsNewCtor extends NewCtor {
! 17: }
! 18: echo "\nInherited new-style constructor\n";
! 19: $methodInfo = new ReflectionMethod("ExtendsNewCtor::__construct");
! 20: var_dump($methodInfo->isConstructor());
! 21:
! 22: class OldCtor {
! 23: function OldCtor() {
! 24: echo "In " . __METHOD__ . "\n";
! 25: }
! 26: }
! 27: echo "\nOld-style constructor:\n";
! 28: $methodInfo = new ReflectionMethod("OldCtor::OldCtor");
! 29: var_dump($methodInfo->isConstructor());
! 30:
! 31: class ExtendsOldCtor extends OldCtor {
! 32: }
! 33: echo "\nInherited old-style constructor:\n";
! 34: $methodInfo = new ReflectionMethod("ExtendsOldCtor::OldCtor");
! 35: var_dump($methodInfo->isConstructor());
! 36:
! 37: class X {
! 38: function Y() {
! 39: echo "In " . __METHOD__ . "\n";
! 40: }
! 41: }
! 42: echo "\nNot a constructor:\n";
! 43: $methodInfo = new ReflectionMethod("X::Y");
! 44: var_dump($methodInfo->isConstructor());
! 45:
! 46: class Y extends X {
! 47: }
! 48: echo "\nInherited method of the same name as the class:\n";
! 49: $methodInfo = new ReflectionMethod("Y::Y");
! 50: var_dump($methodInfo->isConstructor());
! 51:
! 52: class OldAndNewCtor {
! 53: function OldAndNewCtor() {
! 54: echo "In " . __METHOD__ . "\n";
! 55: }
! 56:
! 57: function __construct() {
! 58: echo "In " . __METHOD__ . "\n";
! 59: }
! 60: }
! 61: echo "\nOld-style constructor:\n";
! 62: $methodInfo = new ReflectionMethod("OldAndNewCtor::OldAndNewCtor");
! 63: var_dump($methodInfo->isConstructor());
! 64:
! 65: echo "\nRedefined constructor:\n";
! 66: $methodInfo = new ReflectionMethod("OldAndNewCtor::__construct");
! 67: var_dump($methodInfo->isConstructor());
! 68:
! 69: class NewAndOldCtor {
! 70: function __construct() {
! 71: echo "In " . __METHOD__ . "\n";
! 72: }
! 73:
! 74: function NewAndOldCtor() {
! 75: echo "In " . __METHOD__ . "\n";
! 76: }
! 77: }
! 78: echo "\nNew-style constructor:\n";
! 79: $methodInfo = new ReflectionMethod("NewAndOldCtor::__construct");
! 80: var_dump($methodInfo->isConstructor());
! 81:
! 82: echo "\nRedefined old-style constructor:\n";
! 83: $methodInfo = new ReflectionMethod("NewAndOldCtor::NewAndOldCtor");
! 84: var_dump($methodInfo->isConstructor());
! 85:
! 86: ?>
! 87: --EXPECTF--
! 88: Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d
! 89: New-style constructor:
! 90: bool(true)
! 91:
! 92: Inherited new-style constructor
! 93: bool(true)
! 94:
! 95: Old-style constructor:
! 96: bool(true)
! 97:
! 98: Inherited old-style constructor:
! 99: bool(true)
! 100:
! 101: Not a constructor:
! 102: bool(false)
! 103:
! 104: Inherited method of the same name as the class:
! 105: bool(false)
! 106:
! 107: Old-style constructor:
! 108: bool(false)
! 109:
! 110: Redefined constructor:
! 111: bool(true)
! 112:
! 113: New-style constructor:
! 114: bool(true)
! 115:
! 116: Redefined old-style constructor:
! 117: bool(false)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>