- 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.
- 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.
- Are objects passed by value or by reference? - Everything is passed by value.
- How do you call a constructor for a parent class? - parent::constructor($value)
- 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.
- 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.
- 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.
- 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.
- What is the difference between characters \023 and \x23? - The first one is octal 23, the second is hex 23.
PHP FAQS
PHP Interview question and answers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment