PHP Constants
- What will be the output of the following PHP code ?
<?php
class newObject { }
define('newObject::CONSTANT', 'Example');
echo newObject::CONSTANT;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Class constants cannot be defined or redefined outside class.
- What will be the output of the following PHP code ?
<?php
define("STR_VAR","Interview");
${STR_VAR} = "Mania";
echo STR_VAR;
echo ${STR_VAR};
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
${STR_VAR} creates a new variable which is not same as STR_VAR.
- 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;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Anything starting from 0 is evaluated as an octal.
- 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;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
Constants can be set as values for other constants.
- What will be the output of the following PHP code?
<?php
define('IF', 102);
echo "IF: ", IF;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
A keyword like IF cannot be used as constant names.