@@ -33,7 +33,7 @@ abstract class AbstractClass {
33
33
}
34
34
}
35
35
36
- class TestUser {
36
+ class TestUserWithConstructorArgs {
37
37
public function __construct (int $ int_param , string $ string_param ) {
38
38
return new stdClass ();
39
39
}
@@ -42,70 +42,121 @@ class TestUser {
42
42
}
43
43
}
44
44
45
+ class TestUserWithConstructorNoParams {
46
+ public function __construct () {
47
+ return new stdClass ();
48
+ }
49
+ public function __destruct () {
50
+ echo 'Destructor for ' , __CLASS__ , PHP_EOL ;
51
+ }
52
+ }
53
+
54
+ class TestUserWithoutConstructor {
55
+ public function __destruct () {
56
+ echo 'Destructor for ' , __CLASS__ , PHP_EOL ;
57
+ }
58
+ }
59
+
45
60
echo "Testing impossible initializations \n" ;
46
61
try {
47
62
$ o = zend_object_init_with_constructor ("_ZendTestInterface " );
48
63
var_dump ($ o );
64
+ unset($ o );
49
65
} catch (\Throwable $ e ) {
50
66
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
51
67
}
52
68
try {
53
69
$ o = zend_object_init_with_constructor ("_ZendTestTrait " );
54
70
var_dump ($ o );
71
+ unset($ o );
55
72
} catch (\Throwable $ e ) {
56
73
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
57
74
}
58
75
try {
59
76
$ o = zend_object_init_with_constructor ("ZendTestUnitEnum " );
60
77
var_dump ($ o );
78
+ unset($ o );
61
79
} catch (\Throwable $ e ) {
62
80
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
63
81
}
64
82
try {
65
83
$ o = zend_object_init_with_constructor ("AbstractClass " );
66
84
var_dump ($ o );
85
+ unset($ o );
67
86
} catch (\Throwable $ e ) {
68
87
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
69
88
}
70
89
try {
71
90
$ o = zend_object_init_with_constructor ("SysvMessageQueue " );
72
91
var_dump ($ o );
92
+ unset($ o );
73
93
} catch (\Throwable $ e ) {
74
94
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
75
95
}
76
96
try {
77
97
$ o = zend_object_init_with_constructor ("PrivateUser " );
78
98
var_dump ($ o );
99
+ unset($ o );
79
100
} catch (\Throwable $ e ) {
80
101
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
81
102
}
82
103
try {
83
104
$ o = zend_object_init_with_constructor ("ThrowingUser " );
84
105
var_dump ($ o );
106
+ unset($ o );
85
107
} catch (\Throwable $ e ) {
86
108
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
87
109
}
88
110
89
111
echo "Testing param passing \n" ;
90
112
try {
91
- $ o = zend_object_init_with_constructor ("TestUser " );
113
+ $ o = zend_object_init_with_constructor ("TestUserWithConstructorArgs " );
92
114
var_dump ($ o );
115
+ unset($ o );
93
116
} catch (\Throwable $ e ) {
94
117
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
95
118
}
96
119
try {
97
- $ o = zend_object_init_with_constructor ("TestUser " , "str " , 5 );
120
+ $ o = zend_object_init_with_constructor ("TestUserWithConstructorArgs " , "str " , 5 );
98
121
var_dump ($ o );
122
+ unset($ o );
99
123
} catch (\Throwable $ e ) {
100
124
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
101
125
}
102
126
try {
103
- $ o = zend_object_init_with_constructor ("TestUser " , 5 , string_param: "str " );
127
+ $ o = zend_object_init_with_constructor ("TestUserWithConstructorArgs " , 5 , string_param: "str " , unused_param: 15.3 );
104
128
var_dump ($ o );
129
+ unset($ o );
105
130
} catch (\Throwable $ e ) {
106
131
echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
107
132
}
108
133
134
+ $ o = zend_object_init_with_constructor ("TestUserWithConstructorArgs " , 5 , string_param: "str " );
135
+ var_dump ($ o );
136
+ unset($ o );
137
+
138
+ echo "Passing too many args to constructor \n" ;
139
+ $ o = zend_object_init_with_constructor ("TestUserWithConstructorArgs " , 5 , "str " , 'unused_param ' );
140
+ var_dump ($ o );
141
+ unset($ o );
142
+
143
+ echo "Testing class with defined constructor and no params \n" ;
144
+ $ o = zend_object_init_with_constructor ("TestUserWithConstructorNoParams " );
145
+ var_dump ($ o );
146
+ unset($ o );
147
+
148
+ echo "Testing class without defined constructor \n" ;
149
+ try {
150
+ $ o = zend_object_init_with_constructor ("TestUserWithoutConstructor " , 5 , string_param: "str " );
151
+ var_dump ($ o );
152
+ unset($ o );
153
+ } catch (\Throwable $ e ) {
154
+ echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
155
+ }
156
+ $ o = zend_object_init_with_constructor ("TestUserWithoutConstructor " );
157
+ var_dump ($ o );
158
+ unset($ o );
159
+
109
160
?>
110
161
--EXPECT--
111
162
Testing impossible initializations
@@ -118,8 +169,24 @@ Destructor for PrivateUser
118
169
Error: Call to private PrivateUser::__construct() from global scope
119
170
Exception: Don't construct
120
171
Testing param passing
121
- ArgumentCountError: Too few arguments to function TestUser::__construct(), 0 passed and exactly 2 expected
122
- TypeError: TestUser::__construct(): Argument #1 ($int_param) must be of type int, string given
123
- object(TestUser)#3 (0) {
172
+ ArgumentCountError: Too few arguments to function TestUserWithConstructorArgs::__construct(), 0 passed and exactly 2 expected
173
+ TypeError: TestUserWithConstructorArgs::__construct(): Argument #1 ($int_param) must be of type int, string given
174
+ Error: Unknown named parameter $unused_param
175
+ object(TestUserWithConstructorArgs)#1 (0) {
176
+ }
177
+ Destructor for TestUserWithConstructorArgs
178
+ Passing too many args to constructor
179
+ object(TestUserWithConstructorArgs)#1 (0) {
180
+ }
181
+ Destructor for TestUserWithConstructorArgs
182
+ Testing class with defined constructor and no params
183
+ object(TestUserWithConstructorNoParams)#1 (0) {
184
+ }
185
+ Destructor for TestUserWithConstructorNoParams
186
+ Testing class without defined constructor
187
+ object(TestUserWithoutConstructor)#1 (0) {
188
+ }
189
+ Destructor for TestUserWithoutConstructor
190
+ object(TestUserWithoutConstructor)#1 (0) {
124
191
}
125
- Destructor for TestUser
192
+ Destructor for TestUserWithoutConstructor
0 commit comments