Edwin Rodríguez

Get file and line where a function is called in php


There is the code

function hola() {
  var_dump(debug_backtrace()[0]);
}

function chao() {
  hola();
}

chao();

The output

array(4) {
  ["file"]=>
  string(20) "/home/edwin/hola.php"
  ["line"]=>
  int(8)
  ["function"]=>
  string(4) "hola"
  ["args"]=>
  array(0) {
  }
}

2017 - Edwin Rodríguez