Programming/php

php 상수 선언 - define

구차니 2017. 4. 15. 10:47

define에 의해서 선언된 값은 상수로 변경이 불가능하며(상수니까)

$로 변수 식별자 없이 바로 사용이 가능하다.


<?php

  define ('YEAR',  3000);

  echo YEAR;

?>

[링크 : http://php.net/manual/kr/language.constants.php]


+

Performance results

Test performedTime spentMemory consumed
Using define()100%32.6%
Using class constants30.2%100%
Using apc_define_constants()24.2%32.0%
Using hidef13.9%13.5% (*)

(*) hidef consumes memory during initialization, but this was not taken into account for this test

[링크 : http://shwup.blogspot.com/2010/04/about-constants.html]

    [링크 : http://stackoverflow.com/questions/148185/how-efficient-is-define-in-php]