python里面有这样的用法
#a.py
if __name__ == "__main__":
print "test"
//只有直接python a.py 才会打印test
意思就是当前脚本独立运行时,才会运行print “test”,这在编写模块,并被其他程序调用时,可以用来调试。 php中没有对应的,今天想起来可以这样做:
//a.php
if(count(get_included_files()) == 1){
//This file is not included by other script!
//Do some test here
_test();
//只有直接访问 a.php 时才会执行_test()
//如果b.php中 include("a.php"),则不会执行到 _test()
//达到了和python中的同样效果
}
关于get_included_files, 请参考[这里](http://cn2.php.net/manual/en/function.get- included-files.php)
array get_included_files ( void ) Gets the names of all files that have been included using include(), include_once(), require() or require_once().