Why shouldn't I use UNIVERSAL::isa?

前端 未结 7 998
终归单人心
终归单人心 2021-02-07 07:58

According to this

http://perldoc.perl.org/UNIVERSAL.html

I shouldn\'t use UNIVERSAL::isa() and should instead use $obj->isa() or CLASS->isa().

This means

7条回答
  •  隐瞒了意图╮
    2021-02-07 08:32

    Right. It does a wrong thing for classes that overload isa. Just use the following idiom:

    if (eval { $obj->isa($class) }) {
    

    It is easily understood and commonly accepted.

提交回复
热议问题