August 13th, 2007 - by cpradio

Have you ever wondered what it would be like to interview for a position at Google or Yahoo?

Well at another blog they shared some pre-interview questions from Yahoo for a PHP job. The only problem is they never provided the answers. So that’s what I’m going to do now.

Yahoo, if you’re watching, please check my answers and if they are right, I can start next week! 🙂

Questions 1 – 11

  1. Which of the following will NOT add john to the users array?

    1. $users[] = 'john';
      Successfully adds john to the array
    2. array_add($users,’john’);
      Fails stating Undefined Function array_add()
    3. array_push($users,‘john’);
      Successfully adds john to the array
    4. $users ||= 'john';
      Fails stating Syntax Error
  2. What’s the difference between sort(), assort() and ksort? Under what circumstances would you use each of these?

    1. sort()
      Sorts an array in alphabetical order based on the value of each element. The index keys will also be renumbered 0 to length – 1. This is used primarily on arrays where the indexes/keys do not matter.
    2. assort()
      The assort function does not exist, so I am going to assume it should have been typed asort().

      Like the sort() function, this sorts the array in alphabetical order based on the value of each element, however, unlike the sort() function, all indexes are maintained, thus it will not renumber them, but rather keep them. This is particularly useful with associate arrays.

    3. ksort()
      Sorts an array in alphabetical order by index/key. This is typically used for associate arrays where you want the keys/indexes to be in alphabetical order.
  3. What would the following code print to the browser? Why?

    1. $num = 10;
    2. function multiply(){
    3.     $num = $num * 10;
    4. }
    5. multiply();
    6. echo $num; // prints 10 to the screen

    Since the function does not specify to use $num globally either by using global $num; or by $_GLOBALS[‘num’] instead of $num, the value remains 10.

  4. What is the difference between a reference and a regular variable? How do you pass by reference and why would you want to?

    Reference variables pass the address location of the variable instead of the value. So when the variable is changed in the function, it is also changed in the whole application, as now the address points to the new value.

    Now a regular variable passes by value, so when the value is changed in the function, it has no affect outside the function.

    1. $myVariable = "its' value";
    2. Myfunction(&$myVariable); // Pass by Reference Example

    So why would you want to pass by reference? The simple reason, is you want the function to update the value of your variable so even after you are done with the function, the value has been updated accordingly.

  5. What functions can you use to add library code to the currently running script?

    This is another question where the interpretation could completely hit or miss the question. My first thought was class libraries written in PHP, so include(), include_once(), require(), and require_once() came to mind. However, you can also include COM objects and .NET libraries. By utilizing the com_load and the dotnet_load respectively you can incorporate COM objects and .NET libraries into your PHP code, thus anytime you see “library code” in a question, make sure you remember these two functions.

  6. What is the difference between foo() & @foo()?

    foo() executes the function and any parse/syntax/thrown errors will be displayed on the page.

    @foo() will mask any parse/syntax/thrown errors as it executes.

    You will commonly find most applications use @mysql_connect() to hide mysql errors or @mysql_query. However, I feel that approach is significantly flawed as you should never hide errors, rather you should manage them accordingly and if you can, fix them.

  7. How do you debug a PHP application?

    This isn’t something I do often, as it is a pain in the butt to setup in Linux and I have tried numerous debuggers. However, I will point out one that has been getting quite a bit of attention lately.

    PHP – Advanced PHP Debugger or PHP-APD. First you have to install it by running:
    pear install apd

    Once installed, start the trace by placing the following code at the beginning of your script:

    Then once you have executed your script, look at the log in apd.dumpdir.
    You can even use the pprofp command to format the data as in:
    pprofp -R /tmp/pprof.22141.0

    For more information see

  8. What does === do? What’s an example of something that will give true for ‘==’, but not ‘===’?

    The === operator is used for functions that can return a Boolean false and that may also return a non-Boolean value which evaluates to false. Such functions would be strpos and strrpos.

    I am having a hard time with the second portion, as I am able to come up with scenarios where ‘==’ will be false and ‘===’ would come out true, but it’s hard to think of the opposite. So here is the example I came up with:

    1. if (strpos("abc", "a") == true)
    2. {
    3.     // this does not get hit, since "a" is in the 0 index position, it returns false.
    4. }
    6. if (strpos("abc", "a") === true)
    7. {
    8.     // this does get hit as the === ensures this is treated as non-boolean.
    9. }
  9. How would you declare a class named “myclass” with no methods or properties?

    1. class myclass
    2. {
    3. }
  10. How would you create an object, which is an instance of “myclass”?

    1. $obj = new myclass();

    It doesn’t get any easier than this.

  11. How do you access and set properties of a class from within the class?

    You use the $this->PropertyName syntax.

    1. class myclass
    2. {
    3.     private $propertyName;
    5.     public function __construct()
    6.     {
    7.         $this->propertyName = "value";
    8.     }
    9. }

There you have it! The answers to questions 1 through 11. Stay tuned for Part 2 where I tackle 12 through 22. If you have any questions, need further explanation, or just want to contribute to any of the above questions, comments are always welcome.

22 Responses to “Yahoo Job Interview Questions: Part 1”

1 Dian

This articles rock!

2 Alex

Great post. Thanks a lot!:)

3 Golgotha

Yeah, nice work Matt, I don’t think I would have got the job. But, I could have said, “hey, I work well with people!” 🙂

4 cpradio


Glad you enjoyed it. Golgotha, you are definitely much more of a people person than programmer, but if you spend countless hours with PHP or any language for that matter, it’s amazing how much you never realize you knew until you are tested with such an interview.

Keep an eye out for Part 2, as I was really pleased with myself, I knew which version of PHP introduced GD as “built-in” without looking it up. Anyone care to guess before I release the answer?

5 Roberto Lupi

Regarding Question 8:

“1” == 1 is true
“1” === 1 is false

6 cpradio

Roberto Lupi, excellent. I have no idea why I couldn’t think up an example, must have been a mental roadblock, but thanks for pointing one out.

7 Dan

I’ll tell you from experience that the technical interview is usually only a tiny part of the interview process with these companies, and the theoretical stuff is much harder. You essentially need to have taken discrete math and algorithms/graph theory courses at college level to get through the design & analysis questions. At Google, these came first, with the technical interview (programming questions like these for whatever language the job you’re applying for uses) coming after.

8 Matt

You, sir, did not answer, “How do you pass by reference…”!

9 Hotpoter

Here are some sample questions from GLAT or Google Labs Aptitude Test:

1. Solve this cryptic equation, realizing of course that values for M and E could be interchanged. No leading zeros are allowed.


2. Write a haiku describing possible methods for predicting search traffic seasonality.

3. What number comes next in the sequence:
10, 9, 60, 90, 70, 66

a) 96
b) 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
c) Either of the above
d) None of the above

Source: The Google Story by David A. Vise

10 Yahoo Job Interview Questions: Part 2

[…] you read ‘Yahoo Job Interview Questions: Part 1’ because you were interested in the answers to their questions, then you will definitely be […]

11 Marcin Owczarczyk

Regarding question 8 :
$var==0 – true;
$var===0 – false;


Matt Wilkin’s Blog: Yahoo Job Interview Questions (and Answers) Parts 1 & 2…

13 Jenn

Nice, but what is an “associate array”? I think you mean associative.

14 Mike Borozdin

‘===’ compares the types of the operands first, if they differ it will return ‘false, if they are equal, it will compare their values.

15 Vikas Jayna

What functions can you use to add library code to the currently running script?

While com_load() and dotnet_load() are specific for com objects and dotner libraries, the dl() function can load any .so or .dll file

16 My Ghillie » Yahoo Job Interview Questions: Part 1

[…] Check it out! While looking through the blogosphere we stumbled on an interesting post today.Here’s a quick excerpt […]

17 Chaitanya

There are few more interviews by yahoo at this blog.

Yahoo Interview – 1
Yahoo Interview – 2

18 Rita

Wow….these were quite useful. I also checked out another site with a huge set of questions. Try taking a peek before your interveiw:-

I found it useful

19 Aditya

Explanation on == and === .

1) Operator == is used to check two objects are same or not.
So if 2 objects have same property values and are instances of same class then it returns true else false .

2)operator === is used to check if 2 variables actually refer to same object instance.
ex:- class abc { }
$a= new abc();
then it returns true .

3) example of something that will give true for == and not for === is
clone() function.
cont …. above program

$c= clone($a);
then ($a==$b) returns true ,
but ($a===$b) returns false.

20 Jobs Philippines

Great post! Yahoo sure has some difficult questions!

21 Atanu Dey

Greate Meterials…. Thanks

Finding hard to solve ….

3. What number comes next in the sequence:
10, 9, 60, 90, 70, 66

Confused about the answer “d) None of the above”

What do you say “Yahoo Job Interview Questions: Part 2”?

22 free tutorials

Hey thanks a lot for sharing useful interview questions….. which will be very helpful while attending the interviews…..
glad i found ur site…really a very helpful site…..
by the way check out my collection of php interview questions from here: php interview questions

mulberry sale spyder womens jacket cheap new balance 574 mulberry outlet cheap new balance 574 arcteryx outlet mulberry sale spyder womens jacket mulberry sale spyder womens jacket mulberry outlet mulberry outlet new balance 574

Popular Articles

Top 10 Commentators

Subscribe to this feed! Subscribe by Email!

Random Bits Podcast

You need to download the Flash player from Adobe

Other Sites