如何在PHP4中检查PHP对象是否具有属性。

3

我想检查一个PHP对象是否有某个属性。对于PHP5,我可以使用

if (property_exists($object, "foo")) {...}

但我应该如何在PHP4中实现同样的功能?
2个回答

8

同样的方式:$obj_arr = (array)$object; print isset($obj_arr["foo"]); - gaborous

3
/***
Just as you would do for PHP5, you can apply the same concept for PHP 4. 

***/
//$data is a JSON object am receiving from a  server.
$data = json_decode(stripslashes($_REQUEST['data']));

/****
Applying the same property_exists method but remember to keep both object/class    
and the property to check for in single quotes.
*****/
if (property_exists('data', 'content')) 
{

$content = $data->content;
}

1
欢迎来到StackOverflow。请查看http://stackoverflow.com/help/how-to-answer,了解如何撰写优质答案的相关信息。 - JamesENL

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接