且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在PHP中检查stdClass对象是否为空?

更新时间:2023-11-29 09:25:10

先投射到数组

$tmp = (array) $object;
var_dump(empty($tmp));

原因是,对象是对象,没有空对象"的有用定义,因为那里有足够的类,仅包含方法,而没有属性.他们应该被视为空"吗?

The reason is, that an object is an object and there is no useful definition of "an empty object", because there are enough classes out there, that only contains methods, but no properties. Should they considered as "empty"?