Hello All,

there is a trait which sits in a class. I need the names of the trait methods,
and get_class_methods does this job.
I am happy with that, but is it safe/stable? Is there a better way to get trait 
method names?

Thanks a lot.



Working example (My_Class and My_Trait are in different files):.

----------------------------------------------------------------------------------------------

trait My_Trait {
    function trait_method_1() {}

    function trait_method_2() {}
}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

class My_Class {
    use My_Trait;

    function class_method_1() {
        $trait_methods = get_class_methods( 'My_Trait' );
        print_r( $trait_methods );
    }
    function class_method_2() {}
}

$my_object = new My_Class();
$my_object->class_method_1();


Result:
------------------------
[13-Mar-2013 14:41:22 UTC] Array
(
    [0] => trait_method_1
    [1] => trait_method_2
)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to