php - Executing calling class' method -
class car { $gas= new gas(); $gas->fill( 'filledhandler' ); function filledhandler() { echo 'gas has been filled!'; } } class gas { function fill( $function ) { // here $function(); } }
i need call $function of calling class. right now, it's looking global function
you have pass calling instance.
class car { function fillgas() { $gas = new gas(); $gas->fill($this, 'filledhandler'); } function filledhandler() { echo 'gas has been filled!'; } } class gas { function fill($obj, $function) { // if need class name, use get_class($obj) $obj->$function(); } }
Comments
Post a Comment