Php question on job interview

hey folks,
for someone who is applying for php web developer. what question he might face? and what should he be ready for (that can be asked/to perform in a interview)

Some PHP-specific questions I ask:

What’s the difference between private, protected, and public?

What’s the difference between static and non-static methods? Variables?

How is a static variable different than a constant?

How is const different than declare?

What would you use global for? Give an example of a good use of global parameter.

What is a Singleton, and give me an example of how you would use it?

What is an Iterator, and give me an example of how you would use it?

What do __get() and __set() do? Give an example of a good use for them.

What do __sleep() and __wakeup() do? What would you use them for?

How would you implement a RESTful architecture in PHP?
a. In terms of specifying request method in a browser?
b. In terms of handling the HTTP request and parsing the method on the server?

How is mysqli better than mysql?

What is a stdClass object? How do you create one?

How is a PHP array different than an Array in other languages (e.g. Java)?

What is GD2, and what do you use it for?

How do you open and read an XML file with DOM?

How do you connect to a DB?

How do you load a local file via filesystem?

How do you save a file locally?

How do you submit an HTTP request to a remote server?

How do you load a remote file via HTTP?

Cheers.

really informative steve. thanks!

How is mysqli better than mysql?

I would say Do you use mysql or mysqli, and why?

As Steve said it, it gives away some of the answer. By making them equal, it allows cadidates show that they don’t really know.

/yes a bit evil, but an interview is to weed people out.

We’re actually looking for developers and were coming up with BASIC questions just to test, like Fizzbuzz.
Coding Horror: Why Can’t Programmers… Program?

As it says, a huge amount of CS graduates can’t do it, and it’s simple.

Another one was adding and subtracting numbers using two functions you made (addOne and subtractOne) and basic PHP structures.

Zurev, that FizzBuzz test is awesome!!! I’m gonna start using it!!!

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Here’s my solution:


for ($i = 1; $i <= 100; $i++) {
    $fizzbuzz = ($i % 3 == 0 ? "Fizz" : "").($i % 5 == 0 ? "Buzz" : "");
    echo strlen($fizzbuzz) ? $fizzbuzz : $i;
}

Yeah - When discussing it with my peers I was shocked how many were unable to do it. I mean it’s completely modulus, which is easy enough, however if you weren’t aware of modulus, then it’s a pain. :stuck_out_tongue:

It’s not just modulus, though… it’s also a complex condition that will give insight into how optimal and elegant a person’s code is.

A common solution (the obvious one) is:

if (i %15)
FizzBuzz
else if (i % 3)
Fizz
else if (i %5)
Buzz
else …
i
end

which uses 9 lines.

My solution will be marginally slower, but a lot more elegant. :slight_smile:

I hate parsing through the code of a programmer who doesn’t “think” about the best solution, and just executes on the obvious one… it’s usually 3 times longer than it has to be, and is unnecessarily convoluted.

I call it circumlocutious coding. :smiley:


for ($i=1;$i<=100;$i++,$a=0) {
  echo ((!($i%3) && $a=1)? 'Fizz' : '') . ((!($i%5) && $a=1)? 'Buzz' : '') . (!$a? $i : '');
}

:smiley:

Lol :smiley:


for ($i=1;$i<=100;$i++) echo $i%15?($i%3?($i%5?$i:"Buzz"):"Fizz"):"FizzBuzz";

:wink:

Although I feel that I can answer most of them, would you mind posting some basic answers?

Honestly? I can’t do better than:

[What’s the difference between private, protected, and public?](http://www.google.com/search?q=PHP What’s the difference between private, protected, and public?)

[What’s the difference between static and non-static methods? Variables?](http://www.google.com/search?q=PHP What’s the difference between static and non-static methods? Variables?)

[How is a static variable different than a constant?](http://www.google.com/search?q=PHP How is a static variable different than a constant?)

[How is const different than define?](http://www.google.com/search?q=PHP How is const different than define?)

[What would you use global for? Give an example of a good use of global parameter.](http://www.google.com/search?q=PHP What would you use global for? Give an example of a good use of global parameter.)

[What is a Singleton, and give me an example of how you would use it?](http://www.google.com/search?q=PHP What is a Singleton, and give me an example of how you would use it?)

[What is an Iterator, and give me an example of how you would use it?](http://www.google.com/search?q=PHP What is an Iterator, and give me an example of how you would use it?)

[What do __get() and __set() do? Give an example of a good use for them.](http://www.google.com/search?q=PHP What do __get() and __set() do? Give an example of a good use for them.)

[What do __sleep() and __wakeup() do? What would you use them for?](http://www.google.com/search?q=PHP What do __sleep() and __wakeup() do? What would you use them for?)

[How would you implement a RESTful architecture in PHP In terms of specifying request method in a browser?](http://www.google.com/search?q=PHP How would you implement a RESTful architecture in PHP In terms of specifying request method in a browser?)

[How is mysqli better than mysql?](http://www.google.com/search?q=PHP How is mysqli better than mysql?)

[What is a stdClass object? How do you create one?](http://www.google.com/search?q=PHP What is a stdClass object? How do you create one?)

[How is a PHP array different than an Array in other languages (e.g. Java)?](http://www.google.com/search?q=How is a PHP array different than an Array in other languages (e.g. Java)?)

[What is GD2, and what do you use it for?](http://www.google.com/search?q=PHP What is GD2, and what do you use it for?)

[How do you open and read an XML file with DOM?](http://www.google.com/search?q=PHP How do you open and read an XML file with DOM?)

[How do you connect to a DB?](http://www.google.com/search?q=PHP How do you connect to a DB?)

[How do you load a local file via filesystem?](http://www.google.com/search?q=PHP How do you load a local file via filesystem?)

[How do you save a file locally?](http://www.google.com/search?q=PHP How do you save a file locally?)

[How do you submit an HTTP request to a remote server?](http://www.google.com/search?q=PHP How do you submit an HTTP request to a remote server?)

[How do you load a remote file via HTTP?](http://www.google.com/search?q=PHP How do you load a remote file via HTTP?)

Which question(s) do you feel uncomfortable with, team1504 ?

Hmm, well I apologise I am sound stupid, but the last fand I think I know then, but I am not sure.

The questions on MySQLi or the uniqueness of PHP arrays I have never been tought or read ever.

Thank you for your help and making me a better web programmer!

mysqli is the MySQL-Improved extension… it has many improvements over mysql, including multi-query capabilities, prepared statements, and a native OO construct.

PHP Arrays are different than arrays in other langauges because they’re not really arrays… they’re Collections, more specifically, a combination of an indexed Hash Table and a Stack, optionally using associative keys to reference objects they contain, but also using indices, and introducing push/pop functionality as well. Whereas other languages have multiple data structures to handle all of these functions, PHP combines them all into one - the array.

It depends on what the company does.
Personally I would ask not just php related questions but also couple of questions related to math and couple related to OOP concepts in general.

For example, what is the logarithm? I mean stuff like that, an average programmer may not know it but a programmer with a proper training will know this.

I don’t like to ask any technical questions during the interview.
Instead of it I use the online testing service to screen the candidates. It allows to save a lot of time.

I like this PHP/MySQL test http://tests4geeks.com/test/php-mysql, but you also can checkout BrainBench or Codility.

After I selected the right candidates, I ask them to create simple PHP app at home. Then just compare the code and choose more talent developer.

oops i tried and failed :mad: i wonder when will i get to learn php and be master of it.

I was never that good at taking tests :smiley: but I’m a little surprise that I did better than I thought I would. :slight_smile: