/
illegal-constructor-call-rule-test.php
63 lines (53 loc) · 1.51 KB
/
illegal-constructor-call-rule-test.php
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
<?php
namespace IllegalConstructorMethodCall;
class ExtendedDateTimeWithMethodCall extends \DateTimeImmutable
{
public function __construct(string $datetime = "now", ?\DateTimeZone $timezone = null)
{
// Avoid infinite loop
if (count(debug_backtrace()) > 1) {
return;
}
$this->__construct($datetime, $timezone);
}
public function mutate(string $datetime = "now", ?\DateTimeZone $timezone = null): void
{
$this->__construct($datetime, $timezone);
}
}
class ExtendedDateTimeWithParentCall extends \DateTimeImmutable
{
public function __construct(string $datetime = "now", ?\DateTimeZone $timezone = null)
{
parent::__construct($datetime, $timezone);
}
public function mutate(string $datetime = "now", ?\DateTimeZone $timezone = null): void
{
parent::__construct($datetime, $timezone);
}
}
class ExtendedDateTimeWithSelfCall extends \DateTimeImmutable
{
public function __construct(string $datetime = "now", ?\DateTimeZone $timezone = null)
{
// Avoid infinite loop
if (count(debug_backtrace()) > 1) {
return;
}
self::__construct($datetime, $timezone);
ExtendedDateTimeWithSelfCall::__construct($datetime, $timezone);
}
public function mutate(string $datetime = "now", ?\DateTimeZone $timezone = null): void
{
self::__construct($datetime, $timezone);
ExtendedDateTimeWithSelfCall::__construct($datetime, $timezone);
}
}
class Foo
{
public function doFoo()
{
$extendedDateTime = new ExtendedDateTimeWithMethodCall('2022/04/12');
$extendedDateTime->__construct('2022/04/13');
}
}