I went in an interview with Robert Half Technology yesterday. I took a test of my PHP5 prowess and failed it miserably.
The problem? Not my PHP skillz I assure you. The problem is the test asked questions about stuff in the language I never use. I never learned to do it that way 8 years ago, and just did things the way I already have. If you write PHP, I’ll help you out with some examples.
strstr() - I’ve never used this. Apparently you can do something like, $a = ‘jeremy@jeremyvaught.com”; echo strstr($a, “@”); you get ‘jeremyvaught.com’. The problem is, I’m not on 5.3 yet, so the inverse isn’t true, and why would I use a function that only goes one direction? I’ve always done what I know, which would be something like,
$email = ‘jeremy@jeremyvaught.com’;
echo $name = substr($email, 0, strpos($email, “@”)); //jeremy
echo $url = substr($email, strpos($email, “@”)+1, strlen($email)); //jeremyvaught.com
Obviously strstr is a bit easier, I admit. But until PHP 5.3, I will still have to write the 1st line to get the first part.
The second issue is this. When I’m writing software, and there is something with tricky functionality, I test it thoroughly. Thus I didn’t know off the top of my head that the following is 7.
$a = 1;
echo ++$a * $a++ + a;
I never take the time to ponder that out, I have just, dare I say, stumbled my way through it. Thus I went over this and went over it this morning and disected it until I figured it out. And then I was embarrassed I couldn’t figure it out when it counted. It’s pretty simple in the end.
The answer then if you are like the old me? The obvious is the order of operations, so the multiplication will take place before the addition. (++$a * $a++). Next is the ++. The ++$a increments the variable before the action, and the $a++ after the action. So $a becomes 2 because of the ++$a, and you multiply 2*2, which is 4. But because of the $a++, $a immediately become 3. So when you + $a, you are adding 3 to the already established 4.
Nobody would program like this of course, but it’s cute for testing purposes.
Ok, enough talking about what I just learned, back to learning more.
UPDATE: I forgot the whole reason I wrote this is I was going to paste in here what I responded with back to the Account Executive who interviewed me. Here is what I said,:
Hi [Account Executive],
I just wanted to take a moment and report something back. After I took the PHP5 test yesterday and was shocked how much was in it I didn’t know, I’ve been going through some of the more rudimentary syntax of PHP5 and am remembering how much I have forgotten. I’ve been programming for years, and the stuff I know, I use all the time, and the rest slipped my mind unless I really needed some specific functionality and I looked it up. Long story short, this has been an eye opener as to some of the baser and nuanced workings of the language. And it’s kind of exciting to come back to some this which I haven’t used in years, and probably only read about in a book 8 years ago.
That being said, the test is still very skewed toward this nuanced functionality, but just having taken it is going to make me a better developer because it has forced me to investigate PHP again.
Have a great day!
And I mean every word. The test really has forced me to check out some functionality I’ve been missing out on.