Home >Backend Development >PHP Tutorial >在php扩展开发中如何初始化类里的一个属性默认值为空数组

在php扩展开发中如何初始化类里的一个属性默认值为空数组

WBOY
WBOYOriginal
2016-06-06 20:52:021223browse

需求类似下面的php代码:

class Foo
{
    protected $bar = [];
}

注意不是在构造函数里初始化的哦亲~

先剧透一下……如果直接使用zend_declare_property来初始化一个属性为空数组,会得到以下错误:

Fatal error: Internal zval's can't be arrays, objects or resources in Unknown on line 0

回复内容:

需求类似下面的php代码:

class Foo
{
    protected $bar = [];
}

注意不是在构造函数里初始化的哦亲~

先剧透一下……如果直接使用zend_declare_property来初始化一个属性为空数组,会得到以下错误:

Fatal error: Internal zval's can't be arrays, objects or resources in Unknown on line 0

构造函数, 或者create handler中去初始化,,,这是问题还是?

class Foo
{
    protected $bar = array();
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn