vendredi 15 janvier 2016

Reference to PHP method without using a string

Suppose I have the following PHP code:

class Foo {
    function getBar() {
         return 1;
    }
}

function check( Foo $foo ) {
    if ( $foo->getBar() == 1 ) {
       // here could be more code ...
       return 'Oh no, there was an error in class' . 
              get_class( $foo ) . ', method ' .
              'getBar';
    }
}

The last string in check bothers me because if Foo gets refactored, the error message will be wrong. Is there any way to get around this without using a string somewhere?





Aucun commentaire:

Enregistrer un commentaire