PHP Tutorial

PHP Examples

PHP Practice

PHP Magic Constants Aptitude Questions and Answers

PHP Magic Constants Aptitude: This section contains aptitude questions and answers on PHP Magic Constants. By Nidhi Last updated : December 15, 2023

This section contains Aptitude Questions and Answers on PHP Magic Constants.

1) There are the following statements that are given below, which of them are correct about magic constants in PHP?
  1. Magic constants are defined by the user started with an underscore.
  2. Magic constants are predefined constants that can be changed according to their use.
  3. Magic constants started with a double underscore (__) and end with a double underscore (__).
  4. All of the above

Options:

  1. A and B
  2. A and C
  3. B and C
  4. D

2) Which of the following are the predefined magic constants in PHP?
  1. __LINE__
  2. __TRAIT__
  3. __FILE__
  4. __USER__

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

3) Magic constants are case sensitive?
  1. Yes
  2. No

4) Magic constants are resolved at?
  1. Compile-time
  2. Runtime

5) What is the correct output of the given code snippets?
<?php
$num = 10 + 20;
echo __LINE__;
?>
  1. 30
  2. 3
  3. __LINE__
  4. Error

6) What is the correct output of the given code snippets?
<?php
$num = 10 + 20;
echo "__LINE__";
?>
  1. 30
  2. 3
  3. __LINE__
  4. Error

7) Which of the following magic constant is used to return the complete path of the file with the extension, where it is used?
  1. __PATH__
  2. __FILE__
  3. __DIR__
  4. __FILE_LOC__

8) Which of the following magic constant is used to return the complete directory path, where it is used?
  1. __PATH__
  2. __DIRECTORY__
  3. __DIR__
  4. __LOC__

9) Which of the following are not predefined magic constant?
  1. __PATH__
  2. __DIR__
  3. __LINE__
  4. __CLASS__

10) Which of the following magic constant is used to return the name of the function, where it is used?
  1. __FUN__
  2. __FUNCTION__
  3. __METHOD__
  4. __FUNC__

11) What is the correct output of the given code snippets?
<?php
function fun()
{
    echo __FUNCTION__;
}
fun();
?>
  1. fun
  2. fun()
  3. function fun()
  4. None of the above

12) What is the correct output of the given code snippets in PHP?
<?php
echo __FUNCTION__;
?>
  1. It will print the program name.
  2. It will not print anything.
  3. Error
  4. None of the above

13) Which of the following magic constant is used to return the trait name, where it is used?
  1. __TRIAT__
  2. __TRAIT_NAME__
  3. __TRAIT__
  4. __TR__

14) Which of the following magic constant is used to return the name of the member function of class, where it is used?
  1. __MEMBER__
  2. __FUNCTION__
  3. __METHOD__
  4. None of the above

15) Is there any magic constant, that’s name does not start with a double underscore?
  1. Yes
  2. No

Learn PHP programming with our PHP tutorial.

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.