Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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 from requests方法_Php_Typeerror_Php 7 - Fatal编程技术网

未捕获类型错误:PHP from requests方法

未捕获类型错误:PHP from requests方法,php,typeerror,php-7,Php,Typeerror,Php 7,我的代码中有PHP7的问题 施工类 class FETCH_STRUCTURE{ const FETCH_ARRAY = 0; const FETCH_OBJECT = 1;} public function setPostDataStructure(FETCH_STRUCTURE $postDataStructure) { $this->postDataStructure = $postDataStructure;

我的代码中有PHP7的问题

施工类

class FETCH_STRUCTURE{
    const FETCH_ARRAY     = 0;
    const FETCH_OBJECT    = 1;}
public function setPostDataStructure(FETCH_STRUCTURE $postDataStructure)
    {
            $this->postDataStructure = $postDataStructure;
    }

function getPostDataStructure():FETCH_STRUCTURE {
    return $this->postDataStructure;
}
另一类中的方法

class FETCH_STRUCTURE{
    const FETCH_ARRAY     = 0;
    const FETCH_OBJECT    = 1;}
public function setPostDataStructure(FETCH_STRUCTURE $postDataStructure)
    {
            $this->postDataStructure = $postDataStructure;
    }

function getPostDataStructure():FETCH_STRUCTURE {
    return $this->postDataStructure;
}
从类调用方法

class FETCH_STRUCTURE{
    const FETCH_ARRAY     = 0;
    const FETCH_OBJECT    = 1;}
public function setPostDataStructure(FETCH_STRUCTURE $postDataStructure)
    {
            $this->postDataStructure = $postDataStructure;
    }

function getPostDataStructure():FETCH_STRUCTURE {
    return $this->postDataStructure;
}
未捕获的TypeError:myClass::getPostDataStructure()的返回值必须实现接口FETCH_结构,返回整数


如何解决此问题?

FETCH\u STRUCTURE::FETCH\u ARRAY的值是一个整数(
0
),由
FETCH\u STRUCTURE
中的常量定义。您正在将该值传递给
setPostDataStructure
方法,该方法将该值(
0
)分配给
$this->postDataStructure
属性

getPostDataStructure
的返回值被定义为类
FETCH\u结构
,但实际上您返回的是整数
0

如果要返回整数,则应执行以下操作:

function getPostDataStructure():int {
    return $this->postDataStructure;
}
如果您打算返回
FETCH_结构
类的实例,则应使用
setPostDataStructure
方法设置该类的实例