PHP Interview question and answers
  1. If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b? - 100, it’s a reference to existing variable.

  2. What’s the difference between accessing a class method via -> and via ::? - :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.

  3. Are objects passed by value or by reference? - Everything is passed by value.

  4. How do you call a constructor for a parent class? - parent::constructor($value)

  5. What’s the special meaning of __sleep and __wakeup? - __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

  6. Why doesn’t the following code print the newline properly?    $str = ‘Hello, there.\nHow are you?\nThanks for visiting TechInterviews’;
    print $str;
    Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n.

  7. Would you initialize your strings with single quotes or double quotes? - Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

  8. How come the code works, but doesn’t for two-dimensional array of mine? - Any time you have an array with more than one dimension, complex parsing syntax is required. print “Contents: {$arr[1][2]}” would’ve worked.

  9. What is the difference between characters \023 and \x23? - The first one is octal 23, the second is hex 23.

No comments:

Top Blogs