PHP Constants


  1. What will be the output of the following PHP code?
    <?php
    define("__LINE__", "She is beautiful");
    echo "\n";
    echo __LINE__;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    __LINE__ is a magical constant that gives the current line number and cannot be used as a variable/constant name.


  1. What will be the output of the following PHP code ?
    <?php
    class Constants
    {
    define('MIN_VA', '10.10');
    define('MAX_VAL', '20.20');
    public static function getMin()
    {
    return self::MIN_VAL;
    }
    public static function getMax()
    {
    return self::MAX_VAL;
    }
    }
    echo Constants::getMin();
    echo Constants::getMax();
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In a class constants should be defined const MIN_VAL = 10.10; const MAX_VAL = 20.20; instead.



  1. What will be the output of the following PHP code ?
    <?php
    define('ATTENTION_TEXT', 'Interview mania is good website.', true);
    echo ATTENTION_TEXt;
    $changing_var = 'text';
    echo constant('ATTENTION_' . strtoupper($changing_var));
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    echo constant(c) output c, and c here is the concatenation of ATTENTION_ and $changing_var with . operator.


  1. What will be the output of the following PHP code ?
    <?php
    define("ATTENTION", "Interview mania is good website.", true);
    echo $ATTENTION;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Constants do not need a $ before them, they are referenced by their variable names itself.



  1. What will be the output of the following PHP code ?
    <?php
    define("ATTENTION", "Interview mania is good website.", true);
    echo ATTENTION;
    echo "\n";
    echo ATTENTION;
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Since the third parameter is true in define("ATTENTION", "Interview mania is good website.", true) is true ATTENTION becomes case insensitive.