PHP Output Questions

  1. Find Error/Output in follwing code:
  2.                             
    <?php
    
    class {
       function __construct() {
           echo "In Class A";
       }
    }

    class 
    extends {
       function __construct() {
           echo "In Class B";
       }
    }

    class 
    extends {
    }

    $obj = new C();
    ?>
    1. In Class A
    2. In Class B
    3. No Output
    4. Fatal Error
Answer :
B
Explanation:
Added By : Arpit

  1. Find Error/Output in follwing code:
  2.                             
    <?php
    
    class MyClass
    {
        const 
    CONST_VAR 'Right';
        function 
    showConstant() {
            echo  $this->CONST_VAR;
        }
    }
    $class = new MyClass();
    $class->showConstant();
    ?>
    1. Right
    2. No output
    3. Undefined property
    4. None of the above
Answer :
C
Explanation:
Added By : Anjana


  1. Find Error/Output in follwing code:
  2.                             
    <?php
    
    $email  
    'sumit@gmail.com';
    $user strstr($email'@'true);
    echo 
    $user;
    ?>
    1. sumit
    2. @gmail.com
    3. gmail.com
    4. sumit@
Answer :
A
Explanation:
strstr() returns part of a given string from the first occurrence of a search string to the end of the string. stristr() is idential to strstr() except that it is case insensitive. if pass "true" in third parameter in strstr(string, search_string, true). it returns part of given string before the first occurrence of a search string.
Added By : Sumit

  1. Find Error/Output in follwing code:
  2.                             
    <?php
    
    $val1 
    42;
    if(
    is_numeric($val1)) {
      echo 
    "Integer";
    } else {
      echo 
    "Not Integer";
    }

    $val2 '42';
    if(
    is_numeric($val2)) {
      echo 
    "Integer";
    } else {
      echo 
    "Not Integer";
    }
    ?>
    1. Integer Integer
    2. Integer Not Integer
    3. Not Integer Integer
    4. Not Integer Not Integer
Answer :
A
Explanation:
is_numeric() - Finds whether a variable is a number or a numeric string
Added By : Rohit

  1. Find Error/Output in follwing code:
  2.                             
    <?php
    
    $val1 
    42;
    if(
    ctype_digit($val1)) {
      echo 
    "Integer";
    } else {
      echo 
    "Not Integer";
    }

    $val2 '42';
    if(
    ctype_digit($val2)) {
      echo 
    "Integer";
    } else {
      echo 
    "Not Integer";
    }
    ?>
    1. Not Integer Integer
    2. Integer Not Integer
    3. Integer Integer
    4. Not Integer Not Integer
Answer :
A
Explanation:
ctype_digit - Checks if all of the characters in the provided string, text, are numerical. $val1 = 42. ASCII 42 is the * character and * is not a numeric. function return false.
Added By : Rohit

  1. Find Error/Output in follwing code:
  2.                             
    <?php
    
    $strings 
    'test test';
    if (
    ctype_alpha($strings)) {
      echo 
    "The string consists of all letters.";
    } else {
      echo 
    "The string does not consist of all letters.";
    }
    ?>
    1. The string does not consist of all letters.
    2. The string consists of all letters.
    3. Fatal Error
    4. Syntax Error
Answer :
A
Explanation:
ctype_alpha() returns TRUE if every character in text is a letter[A-Za-z] do not include space, FALSE otherwise.
Added By : Rohit


Post Your Question
Social Sharing
Search