суббота, 2 марта 2013 г.

php отладка ООП кода при помощи Reflection API

однажды один опытный программист на мой вопрос можно ли узнать какие методы у объекта не видя его кода сказал что это не возможно. Сейчас я зная что это не так.
 
<?php
$date = new DateTime("now");
//$date2 = new DateTime("02/03/2013");
$class_info = new ReflectionClass($date);
?>
<pre>
    <?
    Reflection::export($class_info);
    ?>
</pre>
но оказалась что это возможно и данный код дает довольно много инфы
    Class [  class DateTime ] {

  - Constants [11] {
    Constant [ string ATOM ] { Y-m-d\TH:i:sP }
    Constant [ string COOKIE ] { l, d-M-y H:i:s T }
    Constant [ string ISO8601 ] { Y-m-d\TH:i:sO }
    Constant [ string RFC822 ] { D, d M y H:i:s O }
    Constant [ string RFC850 ] { l, d-M-y H:i:s T }
    Constant [ string RFC1036 ] { D, d M y H:i:s O }
    Constant [ string RFC1123 ] { D, d M Y H:i:s O }
    Constant [ string RFC2822 ] { D, d M Y H:i:s O }
    Constant [ string RFC3339 ] { Y-m-d\TH:i:sP }
    Constant [ string RSS ] { D, d M Y H:i:s O }
    Constant [ string W3C ] { Y-m-d\TH:i:sP }
  }

  - Static properties [0] {
  }

  - Static methods [3] {
    Method [  static public method __set_state ] {
    }

    Method [  static public method createFromFormat ] {

      - Parameters [3] {
        Parameter #0 [  $format ]
        Parameter #1 [  $time ]
        Parameter #2 [  $object ]
      }
    }

    Method [  static public method getLastErrors ] {

      - Parameters [0] {
      }
    }
  }

  - Properties [0] {
  }

  - Methods [15] {
    Method [  public method __construct ] {

      - Parameters [2] {
        Parameter #0 [  $time ]
        Parameter #1 [  $object ]
      }
    }

    Method [  public method __wakeup ] {
    }

    Method [  public method format ] {

      - Parameters [1] {
        Parameter #0 [  $format ]
      }
    }

    Method [  public method modify ] {

      - Parameters [1] {
        Parameter #0 [  $modify ]
      }
    }

    Method [  public method add ] {

      - Parameters [1] {
        Parameter #0 [  $interval ]
      }
    }

    Method [  public method sub ] {

      - Parameters [1] {
        Parameter #0 [  $interval ]
      }
    }

    Method [  public method getTimezone ] {

      - Parameters [0] {
      }
    }

    Method [  public method setTimezone ] {

      - Parameters [1] {
        Parameter #0 [  $timezone ]
      }
    }

    Method [  public method getOffset ] {

      - Parameters [0] {
      }
    }

    Method [  public method setTime ] {

      - Parameters [3] {
        Parameter #0 [  $hour ]
        Parameter #1 [  $minute ]
        Parameter #2 [  $second ]
      }
    }

    Method [  public method setDate ] {

      - Parameters [3] {
        Parameter #0 [  $year ]
        Parameter #1 [  $month ]
        Parameter #2 [  $day ]
      }
    }

    Method [  public method setISODate ] {

      - Parameters [3] {
        Parameter #0 [  $year ]
        Parameter #1 [  $week ]
        Parameter #2 [  $day ]
      }
    }

    Method [  public method setTimestamp ] {

      - Parameters [1] {
        Parameter #0 [  $unixtimestamp ]
      }
    }

    Method [  public method getTimestamp ] {

      - Parameters [0] {
      }
    }

    Method [  public method diff ] {

      - Parameters [2] {
        Parameter #0 [  $object ]
        Parameter #1 [  $absolute ]
      }
    }
  }
}

Комментариев нет:

Отправить комментарий

PHP: The Right Way блог програмышки
Яндекс.Метрика