PHP Constants


  1. What will be the output of the following PHP code ?
    <?php
    class newObject { }
    define('newObject::CONSTANT', 'Example');
    echo newObject::CONSTANT;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Class constants cannot be defined or redefined outside class.


  1. What will be the output of the following PHP code ?
    <?php
    define("STR_VAR","Interview");
    ${STR_VAR} = "Mania";
    echo STR_VAR;
    echo ${STR_VAR};
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    ${STR_VAR} creates a new variable which is not same as STR_VAR.



  1. What will be the output of the following PHP code ?
    <?php
    define('OCTAL_NUM1', 0500);
    define('OCTAL_NUM2', 0300);
    print OCTAL_NUM1;
    echo "\n";
    print OCTAL_NUM2;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Anything starting from 0 is evaluated as an octal.


  1. What will be the output of the following PHP code ?
    <?php
    define("FIRST_NAME", "Ajit");
    define("LAST_NAME", FIRST_NAME);

    echo FIRST_NAME;
    echo LAST_NAME;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    Constants can be set as values for other constants.



  1. What will be the output of the following PHP code?
    <?php
    define('IF', 102);
    echo "IF: ", IF;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    A keyword like IF cannot be used as constant names.