property_exists 检查对象或类是否具有该属性
2016-05-04 16:48
453 查看
bool property_exists ( mixed
1.class myClass {
public $mine;
private $xpto;
static protected $test;
static function test() {
var_dump(property_exists('myClass', 'xpto')); //true
}
}
var_dump(property_exists('myClass', 'mine')); //true
var_dump(property_exists(new myClass, 'mine')); //true
var_dump(property_exists('myClass', 'xpto')); //true, as of PHP 5.3.0
var_dump(property_exists('myClass', 'bar')); //false
var_dump(property_exists('myClass', 'test')); //true, as of PHP 5.3.0
myClass::test();
2.class TestClass {
public $declared = null;
}
$testObject = new TestClass;
var_dump(property_exists("TestClass", "dynamic")); // boolean false, as expected
var_dump(property_exists($testObject, "dynamic")); // boolean false, same as above
$testObject->dynamic = null;
var_dump(property_exists($testObject, "dynamic")); // boolean true
unset($testObject->dynamic);
var_dump(property_exists($testObject, "dynamic")); // boolean false, again.
var_dump(property_exists($testObject, "declared")); // boolean true, as espected
unset($testObject->declared);
var_dump(property_exists($testObject, "declared")); // boolean true, even if has been unset()
其他例子参考php官方文档。
$class, string
$property)
1.class myClass {
public $mine;
private $xpto;
static protected $test;
static function test() {
var_dump(property_exists('myClass', 'xpto')); //true
}
}
var_dump(property_exists('myClass', 'mine')); //true
var_dump(property_exists(new myClass, 'mine')); //true
var_dump(property_exists('myClass', 'xpto')); //true, as of PHP 5.3.0
var_dump(property_exists('myClass', 'bar')); //false
var_dump(property_exists('myClass', 'test')); //true, as of PHP 5.3.0
myClass::test();
2.class TestClass {
public $declared = null;
}
$testObject = new TestClass;
var_dump(property_exists("TestClass", "dynamic")); // boolean false, as expected
var_dump(property_exists($testObject, "dynamic")); // boolean false, same as above
$testObject->dynamic = null;
var_dump(property_exists($testObject, "dynamic")); // boolean true
unset($testObject->dynamic);
var_dump(property_exists($testObject, "dynamic")); // boolean false, again.
var_dump(property_exists($testObject, "declared")); // boolean true, as espected
unset($testObject->declared);
var_dump(property_exists($testObject, "declared")); // boolean true, even if has been unset()
其他例子参考php官方文档。
相关文章推荐
- maven org.apache.maven.lifecycle.LifecycleExecutionException
- Opentsdb分布式安装
- linux svn和web同步
- Linux下随机10字符病毒的清除
- kafka+zookeeper环境配置(Mac 或者 linux环境)
- linux中的kill详解
- 2.live555源码分析----服务端doEventLoop()函数分析
- Linux 下 安装 Jmeter
- Ubantu 下安装openssh-server中遇到的一些问题及解决方案
- Linux下chkconfig命令详解
- 【AWS+DaoCloud的应用分享】BootDev如何利用docker在AWS实现超快速自动伸缩
- win7环境下安装Ubuntu kylin 16.04 Lts
- hadoop 集群高可用环境搭建(zookeeper)
- Linux Copy文件
- 网站接入QQ登录
- 基于Hadoop的K-means聚类算法的实现
- Xcopy命令参数使用介绍
- linux 常用命令大全
- 回收linux中cached的内存
- 基于Jcrop的图片上传裁剪加预览