forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzend_object_init_with_constructor.phpt
165 lines (155 loc) · 4.59 KB
/
zend_object_init_with_constructor.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
--TEST--
Zend: Test object_init_with_constructor() API
--EXTENSIONS--
zend_test
sysvmsg
--FILE--
<?php
class PrivateUser {
private function __construct() {
return new stdClass();
}
public function __destruct() {
echo 'Destructor for ', __CLASS__, PHP_EOL;
}
}
class ThrowingUser {
public function __construct() {
throw new Exception("Don't construct");
}
public function __destruct() {
echo 'Destructor for ', __CLASS__, PHP_EOL;
}
}
abstract class AbstractClass {
public function __construct() {
return new stdClass();
}
public function __destruct() {
echo 'Destructor for ', __CLASS__, PHP_EOL;
}
}
class TestUserWithConstructorArgs {
public function __construct(int $int_param, string $string_param) {
return new stdClass();
}
public function __destruct() {
echo 'Destructor for ', __CLASS__, PHP_EOL;
}
}
class TestUserWithConstructorNoParams {
public function __construct() {
return new stdClass();
}
public function __destruct() {
echo 'Destructor for ', __CLASS__, PHP_EOL;
}
}
echo "Testing impossible initializations\n";
try {
$o = zend_object_init_with_constructor("_ZendTestInterface");
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$o = zend_object_init_with_constructor("_ZendTestTrait");
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$o = zend_object_init_with_constructor("ZendTestUnitEnum");
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$o = zend_object_init_with_constructor("AbstractClass");
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$o = zend_object_init_with_constructor("SysvMessageQueue");
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$o = zend_object_init_with_constructor("PrivateUser");
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$o = zend_object_init_with_constructor("ThrowingUser");
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
echo "Testing param passing\n";
try {
$o = zend_object_init_with_constructor("TestUserWithConstructorArgs");
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$o = zend_object_init_with_constructor("TestUserWithConstructorArgs", "str", 5);
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$o = zend_object_init_with_constructor("TestUserWithConstructorArgs", 5, string_param: "str", unused_param: 15.3);
var_dump($o);
unset($o);
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
$o = zend_object_init_with_constructor("TestUserWithConstructorArgs", 5, string_param: "str");
var_dump($o);
unset($o);
echo "Passing too many args to constructor\n";
$o = zend_object_init_with_constructor("TestUserWithConstructorArgs", 5, "str", 'unused_param');
var_dump($o);
unset($o);
echo "Testing class with defined constructor and no params\n";
$o = zend_object_init_with_constructor("TestUserWithConstructorNoParams");
var_dump($o);
unset($o);
?>
--EXPECT--
Testing impossible initializations
Error: Cannot instantiate interface _ZendTestInterface
Error: Cannot instantiate trait _ZendTestTrait
Error: Cannot instantiate enum ZendTestUnitEnum
Error: Cannot instantiate abstract class AbstractClass
Error: Cannot directly construct SysvMessageQueue, use msg_get_queue() instead
Error: Call to private PrivateUser::__construct() from global scope
Exception: Don't construct
Testing param passing
ArgumentCountError: Too few arguments to function TestUserWithConstructorArgs::__construct(), 0 passed and exactly 2 expected
TypeError: TestUserWithConstructorArgs::__construct(): Argument #1 ($int_param) must be of type int, string given
Error: Unknown named parameter $unused_param
object(TestUserWithConstructorArgs)#1 (0) {
}
Destructor for TestUserWithConstructorArgs
Passing too many args to constructor
object(TestUserWithConstructorArgs)#1 (0) {
}
Destructor for TestUserWithConstructorArgs
Testing class with defined constructor and no params
object(TestUserWithConstructorNoParams)#1 (0) {
}
Destructor for TestUserWithConstructorNoParams