PHP错误注意:哈希函数中的数组到字符串转换
我想使用PHP-OOP构建区块链 我的代码:PHP错误注意:哈希函数中的数组到字符串转换,php,arrays,string,constructor,blockchain,Php,Arrays,String,Constructor,Blockchain,我想使用PHP-OOP构建区块链 我的代码: class Block { public function __construct($timestamp, $transactions, $previousHash = null) { $this->previousHash = $previousHash; $this->timestamp = $timestamp; $this->t
class Block {
public function __construct($timestamp, $transactions, $previousHash = null) {
$this->previousHash = $previousHash;
$this->timestamp = $timestamp;
$this->transactions = $transactions;
$this->nonce = 0;
$this->hash = $this->calculateHash();
$this->difficulty = 2;
}
/** Returns the SHA256 of this block (by processing all the data stored inside this block)*/
public function calculateHash() {
return hash("sha256", $this->previousHash.$this->timestamp.((string)$this->transactions).$this->nonce);
}
}
它向我显示了以下错误:
PHP Notice: Array to string conversion in /home/istabraq/bctest/test2/a2.php on line 14
有什么想法吗?将数组转换为字符串可以使用函数:
public function calculateHash() {
return hash("sha256", $this->previousHash.$this->timestamp.(implode('', $this->transactions)).$this->nonce);
}
string$this->transactions不会执行您期望的操作