【问题标题】:Overloading method of comparison for custom class自定义类的比较重载方法
【发布时间】:2012-05-15 12:16:38
【问题描述】:

我想为个人类重载比较方法。

例如,如果我这样写:$object1

function compare($a, $b){
    if($a->attribute == $b->attribute){return 0;}
    else{return $a->attribute > $b->attribute ? 1 : -1;}
}

有没有办法做到这一点?

我已经看过 thisthis 但我无法使用这些解决方案

【问题讨论】:

    标签: php object comparison overloading


    【解决方案1】:

    您在上面提到的 PECL 解决方案是您唯一的选择。 PHP 不提供其他语言中可用的运算符重载。

    【讨论】:

    • 好的,这不是我所期望的答案,但感谢您的回答;)现在我要实施另一个解决方案
    猜你喜欢
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    • 1970-01-01
    • 2017-02-07
    • 2012-06-30
    相关资源
    最近更新 更多