これを複製したい:
$myObject = new object( __FILE__ );
class object {
protected $path_to_caller;
public function __construct( $file ){
$this->path_to_caller = dirname( $file );
}
}
すべての呼び出しで同じになるため、パラメーターを渡す必要はありません。を使用せずにメンバー関数内で呼び出し元のファイル/ディレクトリにアクセスする方法はありますdebug_backtrace()
か?
基本的に、私は欲しい:
$myObject = new object();
class object {
protected $path_to_caller;
public function __construct(){
$this->path_to_caller = special_function(); // dirname( __FILE__ ) of caller
}
}