Test for Interface membership

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bingomanatee

    #1

    Test for Interface membership

    Is there any way to determine if a class is a member of an interface?
    For a concrete example: I am implementing a "node" (Node_if) interface
    on database record representing objects (children of the abstract class
    Data_class) that reflects that certain records have a parent-chld
    relationship. (Others do not).

    I'm generating a library Ordering_class that handles sorting operations
    (i.e., users view a report of ordered objects and can move a specific
    record up or down the listing with methods like
    Ordering_class: :move_up(Data_c lass $obj) ).

    Naturally the ordering behavior of Node_if members will be different
    than the ordering behavior of "flat" tables. (reordering behavior of
    Node_if members will be restricted to siblings; reordering of
    non-Node_if members can affect any member of the table)

    Is there any way for Ordering_class: :move_up(Data_c lass $obj) to test
    $obj to determine that it is or is not a member of Node_if?

  • ZeldorBlat

    #2
    Re: Test for Interface membership

    Check out is_a() and is_subclass_of( );

    Checks whether the object is of a given type or subtype

    Checks if the object has this class as one of its parents or implements it


    Comment

    • Colin McKinnon

      #3
      Re: Test for Interface membership

      ZeldorBlat wrote:
      [color=blue]
      > Check out is_a() and is_subclass_of( );
      >
      > http://www.php.net/manual/en/function.is-a.php
      > http://www.php.net/manual/en/functio...ubclass-of.php[/color]

      PHP 5 *does* do interfaces, but I fail to excited about them - everytime
      I've needed to know that much about an object, I just use method_exists()
      or is_set().

      HTH

      C.

      Comment

      Working...