Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP错误注意:哈希函数中的数组到字符串转换_Php_Arrays_String_Constructor_Blockchain - Fatal编程技术网

PHP错误注意:哈希函数中的数组到字符串转换

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

我想使用PHP-OOP构建区块链

我的代码:

    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不会执行您期望的操作