1. 2013.05.24 PHP Closing Tag
  2. 2008.02.15 php 소스 보여주기

PHP Closing Tag

The PHP closing tag on a PHP document ?> is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files should OMIT the closing PHP tag, and instead use a comment block to mark the end of file and it's location relative to the application root. This allows you to still identify a file as being complete and not truncated.


INCORRECT: 

<?php echo "Here's my code!"; ?> 


CORRECT: 

<?php echo "Here's my code!"; 
/* End of file myfile.php */
/* Location: ./system/modules/mymodule/myfile.php */



** 한국어로 요약**

파일 끝에 스페이스나 엔터가 들어가면 php파일의 output이 생깁니다.

output이 생기면 웹서버에서 헤더를 씌우고 출력을 내보냅니다.


요즘 프로그래밍 방식인 MVC 프로그래밍에서는 (모델, 뷰, 컨트롤러, 핼퍼, 라이브러리 등등)  많은 것을 로드하고 사용해야 합니다.

그런데 실수로 파일에 스페이스바(공백)가 들어가버리면 망하므로 인클루드 될 모듈파일은 되도록 php closing tag는 안쓰는게 좋습니다.


즉 화면에 아무런 출력이 필요없는 파일이면 (곧 소스 전체가 php이면) close tag 를 생략하는 것이 좋습니다.

(아 물론 일반 코딩에서는 닫으셔야 합니다.)

<body>
<?php
echo "hello world!";
?>
</body>


이런 코드를 짜신다면 당연히 닫아야 겠죠?


출처: https://lael.be/171

'WebDevelop > PHP' 카테고리의 다른 글

heredoc syntax  (0) 2008.10.22
Window APM + curl 연동  (0) 2008.06.27
윈도우 APM 환경에서 mail() 함수 사용  (0) 2008.06.15

php 소스 보여주기

	show_source(__FILE__);
Return top