[lang-ref] ソースファイル名(パス)を取得 ( php )
<?php
public function testGetSourceFilePath(): void
{
// __FILE__
/* examples/get_source_file_path.php
<?php
function printFilePath(): void
{
echo(__FILE__);
}
if (realpath($argv[0]) === __FILE__) {
printFilePath();
}
*/
/* examples/get_source_file_path_call.php
<?php
require_once('get_source_file_path.php');
printFilePath();
*/
$out = shell_exec('php examples/get_source_file_path.php');
$this->assertStringEndsWith('/examples/get_source_file_path.php', $out);
$out = shell_exec('php examples/get_source_file_path_call.php');
$this->assertStringEndsWith('/examples/get_source_file_path.php', $out);
}