PHP 매직상수 __FILE__

(PHP FILE에서 넘어옴)

1 개요[ | ]

PHP 매직상수 __FILE__
PHP __FILE__
Console
Copy
root@zetawiki:~# echo "<?php var_dump(__FILE__);" > /tmp/test.php
root@zetawiki:~# php /tmp/test.php 
string(13) "/tmp/test.php"

2 심볼릭 링크인 경우[ | ]

Console
Copy
root@wsl:/tmp/dir1# ll
total 96
drwxr-xr-x   3 root root  4096 Oct 11 00:51 .
drwxrwxrwt 974 root root 81920 Oct 11 00:51 ..
drwxr-xr-x   2 root root  4096 Oct 11 00:51 dir2
-rw-r--r--   1 root root    28 Oct 11 00:50 file1.php
lrwxrwxrwx   1 root root     9 Oct 11 00:51 file2.php -> file1.php
Console
Copy
root@wsl:/tmp/dir1# cat file1.php
<?php
echo __FILE__."\n";
Console
Copy
root@wsl:/tmp/dir1# php file1.php
/tmp/dir1/file1.php
→ file1.php 파일을 실행하면 file1.php의 절대경로를 보여준다.
Console
Copy
root@wsl:/tmp/dir1# php file2.php
/tmp/dir1/file1.php
→ 심볼릭 링크인 file2.php를 실행해도 원래 파일 file1.php의 절대경로를 보여준다.

3 같이 보기[ | ]

4 참고[ | ]