PHP OO Interviewee Test Questions

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

PHP OO Interviewee Test Questions

Post by Grim... »

I used to post on this forum quite a lot, but it's been ages. So hello to all that remember me. [edit]My last post was in September 2007!

I am interviewing for new code monkeys. The test we currently give code monkeys to fill in is rather old and dull. Here is one of the current questions:

Code: Select all

What is the output of the following code?
<?
function r($p) {
    if ($p==1) {
        return 1;
    } else {
        return $p*r($p-1);
    }
}
echo r(5);
?>
Here is another:

Code: Select all

There are no errors when the following code is executed but is does not function as expected.  What is missing?
 
    $user = array(  1 => array('name' => 'john',  'email' => 'john@tpoll.com'),
            2 => array('name' => 'barry', 'email' => 'barry@tpoll.com'),
            3 => array('name' => 'bob',   'email' => 'bob@tpoll.com'));
 
    //LIST EMAILS
    while (list($id, $user_array) = each($user)) {
        print $user_array['email']."<br>";
    }
    
    
    //LIST NAMES
    while (list($id, $user_array) = each($user)) {
        print $user_array['name']."<br>";
    }
I need various questions, because I want everyone to get some right and some wrong. I've written the easy ones, but writing harder ones is more difficult because something I find hard might be easy to someone else, and vice-versa.

So, if any of you can thing of a hard question about PHP (specifically OO-type stuff) (or MySQL, if you are bored) that can be answered without having to write an essay, I would be interested in seeing them.
Better include the answers, too ;)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP OO Interviewee Test Questions

Post by VladSun »

Q: How's this pattern called:

Code: Select all

final class HelloWorld{     protected static $_instance;    public $message = 'Hello, world';     private function __construct()    { }     private function __clone()    { }     public static function getInstance()     {      if( self::$_instance === NULL ) {        self::$_instance = new self();      }      return self::$_instance;    }     public function action()     {      echo $this->message;    }} $instance = HelloWorld::getInstance();$instance->action();
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP OO Interviewee Test Questions

Post by Christopher »

I think patterns would be a good higher-level thing to ask about.

Probably the most basic OO thing to check is use $this->var rather than $var. That is a really common error. And following on that, perhaps a more complex questions about composition. And following that, questions about inheritance -- method overloading, etc.
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: PHP OO Interviewee Test Questions

Post by alex.barylski »

First you have to define the term code monkey and their expectations/responsibilities/etc.

A code monkey, to me, is someone with a very basic understanding of programming concepts, maybe 1-2 years experience. I wouldn't expect them to know much about OOP, design patterns, practices, etc.

I would test their algorithm/problem solving skills more than anything, their ability to stay consistent and follow requests. I don't want junior developers introducing new classes, changing any interface, etc without my approval, so I could care less about how well they comprehend inhertence, composition, patterns, etc. and more about how well they write code, is it sloppy (inconsistent), give them a problem which would cause duplication at first sight and later be refactored into a member.

Have a conventions document (more pedantic the better) and have them read it. Have them write code and see how well they conform to the document conventions. It's incredible how many people fail this simple, yet important test.

Cheers,
Alex
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: PHP OO Interviewee Test Questions

Post by Darhazer »

Once we've wrote the following 'test'for OO:

You have a class, that implement interface IDraw, with method draw(), and draws a rectangle.
You have another class, that implements the same interface, with method draw() and draws a circle.
Write a class, that renders rectangle with a X in it.

The expected solution is to create a class, implementing IDraw and rendering X, and than to use Composite pattern, to create the rectangle with X.

Another approach, but not the preferred one (by our team), is to extends the rectangle class.
And if you just create a new class that renders both, without extending the rectangle or use it in a composite, it's considered as a failure. ;)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP OO Interviewee Test Questions

Post by VladSun »

OK... A PHP specific OOP question:
Q: What's the output of:

Code: Select all

<?php class MyClass{    private function __call($m, $a)    {        var_dump($m);        var_dump($a);    }}  $var = new MyClass(); $var->sqrt(6);$var->round(2.51);
There are 10 types of people in this world, those who understand binary and those who don't
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHP OO Interviewee Test Questions

Post by josh »

<offtopic>
PCSpectra wrote:A code monkey, to me, is someone with a very basic understanding of programming concepts, maybe 1-2 years experience. I wouldn't expect them to know much about OOP, design patterns, practices, etc.
When job titles include "ninja" or "monkey" it raises a huge red flag to me. I won't lie and say its a deal breaker, but lets just say you offended me and aren't going to get as low of a salary should I accept. I'm a regular person, not a primate. It also shows (to me) you don't know any solid criteria to make hiring decisions on.
</offtopic>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP OO Interviewee Test Questions

Post by AbraCadaver »

josh wrote:<offtopic>
PCSpectra wrote:A code monkey, to me, is someone with a very basic understanding of programming concepts, maybe 1-2 years experience. I wouldn't expect them to know much about OOP, design patterns, practices, etc.
When job titles include "ninja" or "monkey" it raises a huge red flag to me. I won't lie and say its a deal breaker, but lets just say you offended me and aren't going to get as low of a salary should I accept. I'm a regular person, not a primate. It also shows (to me) you don't know any solid criteria to make hiring decisions on.
</offtopic>
How about "pirate"?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP OO Interviewee Test Questions

Post by Eran »

How about the following test then:
Complete the following sentence:
"I want to be a code ... "
1. Ninja
2. Monkey
3. Pirate
4. Cowboy
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP OO Interviewee Test Questions

Post by Benjamin »

Why not just view some code samples?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHP OO Interviewee Test Questions

Post by josh »

AbraCadaver wrote: How about "pirate"?
Does that mean I get to violate DMCA? If so then yeah I'd accept that job.

Actually today I interviewed for a "ninja" position. The questions were like "what is the difference between an abstract class and an interface". Another was "what would you do if someone asked you to do something stupid". My answer to the latter was to the effect of I would try to ask them the goal of doing this "stupid" thing and see if I could suggest a better way, or educate the person on why what they asked was stupid. If they still asked me to do "stupid" stuff daily I'd be gone, is what I told them.

At the end the guy said I'm high on his list but I'm not sure if I even want the position.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Re: PHP OO Interviewee Test Questions

Post by Grim... »

VladSun wrote:OK... A PHP specific OOP question:
Q: What's the output of:

Code: Select all

<?php class MyClass{    private function __call($m, $a)    {        var_dump($m);        var_dump($a);    }}  $var = new MyClass(); $var->sqrt(6);$var->round(2.51);
I'm guessing it would be something like "Warning: The magic method __call() must be public" ;)

But that's a good one - cheers. And thanks to everyone else for your input, too.

And sorry to anyone if I offended with the phrase 'code monkey' - I use it to cover people of any level that code for a living (myself included).
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: PHP OO Interviewee Test Questions

Post by onion2k »

Darhazer wrote:Once we've wrote the following 'test'for OO:

You have a class, that implement interface IDraw, with method draw(), and draws a rectangle.
You have another class, that implements the same interface, with method draw() and draws a circle.
Write a class, that renders rectangle with a X in it.

The expected solution is to create a class, implementing IDraw and rendering X, and than to use Composite pattern, to create the rectangle with X.

Another approach, but not the preferred one (by our team), is to extends the rectangle class.
And if you just create a new class that renders both, without extending the rectangle or use it in a composite, it's considered as a failure. ;)
I would expect you to get candidates extending the rectangle object most of the time there simply because there's no reason to go as far as using a composite. Whoever wrote the question isn't very good at spec'ing things.

Don't forget that as much as an interview is for you to find out about a candidate, it's for them to find out about working for your company. If I was given that question and talked through the "expected" answer, I'd be very dubious about accepting a job with you. If you can't make it clear what you want in something that basic what are your specs like for real deliverables?!
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Re: PHP OO Interviewee Test Questions

Post by Grim... »

I am as interested in the ones they get wrong as the ones they get right, if you see what I mean.

The last two questions on the test are "Do you think employees should be allowed to access Facebook during work hours?" and "Draw a pig." :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP OO Interviewee Test Questions

Post by VladSun »

Grim... wrote:I'm guessing it would be something like "Warning: The magic method __call() must be public" ;)
I have no error/warning messages ...

error_reporting(E_ALL|E_STRICT); // error log file is empty
PHP Version 5.2.10

And I really think magic methods should be protected/private - one should not be able to run them directly.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply