Questions tagged «php-7.4»

2
为什么在引入属性类型提示时突然出现“初始化前不能访问类型化属性”错误?
我已经更新了类定义,以利用新引入的属性类型提示,如下所示: class Foo { private int $id; private ?string $val; private DateTimeInterface $createdAt; private ?DateTimeInterface $updatedAt; public function __construct(int $id) { $this->id = $id; } public function getId(): int { return $this->id; } public function getVal(): ?string { return $this->val; } public function getCreatedAt(): ?DateTimeInterface { return $this->createdAt; } public …

3
ArrayObject不适用于PHP 7.4中的end()
在迁移到PHP 7.4时,我必须处理某些数组函数(例如reset(),current()或end()涉及ArrayObject)的不同行为。以下示例产生不同的输出: <?php $array = new \ArrayObject(["a", "b"]); $item = end($array); var_dump($item); $array = ["a", "b"]; $item = end($array); var_dump($item); 使用php 7.4的输出是: bool(false) string(1) "b" 在7.4之前的PHP版本上,输出如下: string(1) "b" string(1) "b" A end($array->getArrayCopy())会发出通知,但如果与变量一起使用,可能会变通。 有没有办法模仿的行为end()与一个ArrayObject或ArrayIterator?ArrayObject可能非常大,到最后的迭代可能不是最佳解决方案。
9 php  php-7.4 


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.