Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b655e2

Browse files
add test for class with private constructor which currently triggers an assertion failure
1 parent a75901c commit 0b655e2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎ext/reflection/tests/ReflectionClass_newInstanceFromData_002.phpt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ $rcMyInterface = new ReflectionClass('MyInterface');
1616
trait MyTrait {}
1717
$rcMyTrait = new ReflectionClass('MyTrait');
1818

19+
// class with private constructor
20+
class A
21+
{
22+
public int $a;
23+
24+
private function __construct()
25+
{
26+
echo "In constructor of class A\n";
27+
}
28+
}
29+
30+
$rcA = new ReflectionClass('A');
31+
1932
try
2033
{
2134
$rcDateTime->newInstanceFromData([], ['now', new DateTimeZone('UTC')]);
@@ -52,9 +65,19 @@ catch(Throwable $e)
5265
echo "Exception: " . $e->getMessage() . "\n";
5366
}
5467

68+
try
69+
{
70+
$rcA->newInstanceFromData(['a' => 123]);
71+
}
72+
catch(Throwable $e)
73+
{
74+
echo "Exception: " . $e->getMessage() . "\n";
75+
}
76+
5577
?>
5678
--EXPECTF--
5779
Exception: Class DateTime is an internal class that cannot be instantiated from data
5880
Exception: Class PDOStatement is an internal class that cannot be instantiated from data
5981
Exception: Cannot instantiate interface MyInterface
6082
Exception: Cannot instantiate trait MyTrait
83+
Exception: Access to non-public constructor of class A

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /