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