Skip to content

Commit

Permalink
StaticClass: constructor is private [Closes nette/di#292]
Browse files Browse the repository at this point in the history
- ReflectionClass::isInstance() returns false
- it is marked as an error in the IDE
  • Loading branch information
dg committed Aug 29, 2023
1 parent 96f462d commit 599c3d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/StaticClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
trait StaticClass
{
/**
* @return never
* @throws \Error
* Class is static and cannot be instantiated.
*/
final public function __construct()
final private function __construct()
{
throw new \Error('Class ' . static::class . ' is static and cannot be instantiated.');
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/StaticClass.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestClass
Assert::exception(
fn() => new TestClass,
Error::class,
'Class TestClass is static and cannot be instantiated.',
'Call to private TestClass::__construct() from global scope',
);

Assert::exception(
Expand Down

0 comments on commit 599c3d1

Please sign in to comment.