Check if PHP object can be compared
Some PHP objects such as instances of DateTime can be compared with greater than or less than. Given
$time_1 = new DateTime('2016-02-24 15:22:01');
$time_2 = new DateTime('2016-01-30 10:41:29');
then the comparison time_1<time_2
is valid and will evaluate to false.
Comparisons like this can't be done for objects we create from our own classes.
Given an object, is it possible to determine whether it can be compared with the greater than or less than symbols?
Edit:
I'd like some way to test an object is from a class which has overloaded the comparison operators. Eg:
class MyClass {}
$obj_1 = new MyClass();
$obj_2 = new DateTime();
has_overloaded( $obj_1 ); //false
has_overloaded( $obj_2 ); //true
链接地址: http://www.djcxy.com/p/58590.html
上一篇: 如果大于C#
下一篇: 检查是否可以比较PHP对象