有这么一段代码
<?php
class Calendar {
public \DateTimeImmutable $start;
public \DateTimeImmutable $now;
public \DateTimeImmutable $end;
public \DateInterval $calendarInterval;
public \DateInterval $dayInterval;
public \DatePeriod $period;
public function __construct() {
$this->now = new \DateTimeImmutable();
$this->calendarInterval = new \DateInterval('P1D');
$this->dayInterval = new \DateInterval('P1D');
}
public function compareObjects(): void {
$this->start = $this->now->sub($this->calendarInterval);
$this->end = $this->now->add($this->calendarInterval);
$this->period = new \DatePeriod($this->start, $this->dayInterval, $this->end, \DatePeriod::INCLUDE_END_DATE);
}
}
$obj = new Calendar();
$obj->compareObjects();
foreach($obj->period as $day) {
echo $day->format('d.m.o l') . "\n";
echo var_dump($obj->now == $day);
}
当我使用常量时\DatePeriod::INCLUDE_END_DATE
出现错误
PHP Fatal error: Uncaught Error: Undefined constant DatePeriod::INCLUDE_END_DATE in /var/www/native/src/test.php:19
Stack trace:
#0 /var/www/native/src/test.php(24): Calendar->compareObjects()
#1 {main}
thrown in /var/www/native/src/test.php on line 19
当我使用\DatePeriod::EXCLUDE_START_DATE
同一个类的常量时,一切正常。结论如下
27.02.2024 Tuesday
/var/www/native/src/test.php:27:
bool(true)
我在文档中没有找到有关过时常量的任何信息。
为什么???
1 个回答