在php 8.1 及以上版本中,直接运行上面的PDO代码会出现类似于:

Return type of TableRows::current() should either be compatible with RecursiveIteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in xxx

的报错,这是因为新版本的php在从标准库扩展类时,重载函数强制要求添加返回类型。将TableRows类作如下修改即可:

class TableRows extends RecursiveIteratorIterator {

function __construct($it) {

parent::__construct($it, self::LEAVES_ONLY);

}

function current(): string {

return "" . parent::current(). "";

}

function beginChildren(): void {

echo "";

}

function endChildren(): void {

echo "" . "\n";

}

}2333 2333

106***5971@qq.com

参考地址

3年前 (2022-11-16)