PHP is not Java

Nov 29th, 2010

I went for an Interview and there interviewer asked me few questions. I disagreed on two questions and their answers. According to interviewer, it is must to use parenthesis while initializing class( new className()), but I said if it requires parameters then it is essential otherwise it is not. After I disagreed they said it is essential in new PHP version 5.2.x. Still I disagreed then he said, no no after PHP 5.2.x, PHP is like Java.
Second question was about constructors. I said parent constructor will not be called when I initialize derived class that has its own constructor. He answered that no it will called. I said, it is in Java and not in PHP. So, again he said, PHP has everything now and it is like Java. I like PHP and I do not want it to become Java. If just by implementing Object Oriented Programming, it can be said, PHP is following Java then I will say Java is following C++ or Java copied C++.

Because he denied so convincingly that my answer is wrong according to new changes in PHP, so I thought to check myself. I found my answer was correct.

Now, if he remember and show the courage to correct himself and accept his mistake then at least these two questions will not be the criteria for not selecting me!

<?php

class base {

	public function __construct() {
		echo '<p>base class</p>';
	}
}

class derived extends base {

	public function __construct() {

		echo '<p>derived class</p>';
	}
}

$obj1 = new derived;

echo PHP_VERSION;

Output:
derived class
5.3.1

Except, echo statement content, this was the code I have written there.

Above, I have not used parenthesis at the time of initialization and parent class constructor has not called automatically when I initialize derived class. and my PHP version is 5.3.1.

Update:
One may think how these kind of questions come for discussion.
Actually the question they asked was to create a base class and a derived class. and write echo statements in constructors. So, I have written that on paper. After seeing my code he got two questions and that is what I have written above. One bad point is I never been a part of greenfield project based on complete Object oriented implementation.
In few days, it will be confirmed about my selection there. If they did not select me then I will disclose the company name here to add more spice to this post.
I am inspired to know that PHPdeveloper.org has mentioned this post.

Update:
Ok. I am not mentioning the company name and Interviewer name but those who know can understand a little when I say that company is a IT development center or complete development center (I mean they may be taking outside work as well) for an University. It is situated in Ashwini Layout, Koramangala, Bangalore.
I did not like them because they have not introduced themselves (2 interviewer were there) and only asked few questions. and Not selected me (too bad :) ).

 
  1. November 29th, 2010 at 18:50 | #1

    Hopefully whoever was interviewing you will read this and realize their mistakes. I’m guessing you did not get the job?

  2. Andy Till
    November 29th, 2010 at 19:08 | #2

    In your face interviewer!

  3. November 29th, 2010 at 19:15 | #3

    @Phil Sturgeon
    You are right in second line. For first sentence I can say I cannot hope for that.

  4. November 29th, 2010 at 19:17 | #4

    @Andy Till
    Sorry, I did not get you.

  5. Andi
    November 29th, 2010 at 21:45 | #5

    Sorry to hear. But I’d be wondering if I’d really want to work for a company like that.

    • November 29th, 2010 at 22:22 | #6

      Here, in India, at most places the case is like that (Here people become Manager and leader very soon). I saw a CTO who cannot correct a PHP subjective interview questions even after giving answer sheet. So, he distributed old question paper in exam so he can match with many earlier answer sheets he know corrected earlier by someone.

  6. Thomas
    November 30th, 2010 at 02:32 | #7

    If I would read an blog entry like this, I would never hire you.
    The company, or to be more specific, the interviewer was obviously wrong.
    “Adding more spice to the post” as a kind of revenge is exactly that kind of attitude which is futile for any team project.
    Perhaps something you want to consider for the future.

  7. English checker
    November 30th, 2010 at 08:01 | #8

    It’s “their interviewer” not “there interviewer”

  8. November 30th, 2010 at 08:36 | #9

    @Thomas Ok. somehow you have a point. But here politics and personal tuning work more than real work. and those who think that way is made to work for work (good but) without any benefits.
    I also saw that if you say I work for company then you get a lots of bad point from immediate manager. and he will make you work like a hell without any benefits. I have not made the name public as you see but later I thought to do so. Much for making the reading interesting. Still I have not done that in second update, you see. So, I was in control. But here game is different. Good is labeled as poor boy.
    and Thomas, you see I have objected their points and put my point convincingly but they just rejected it. Only good point they objected that and speak up their mind. With many years of experience I have , they should do not suppose me to just listen! My putting forward my case should not be regarded as argumen?

  9. November 30th, 2010 at 09:29 | #10

    also worth noting that in java, sometimes you do have to explicitly call the parent constructor, such as a no arg constructor

  10. November 30th, 2010 at 10:59 | #11

    Hey Satya,

    Thanxs for sharing ur experience … well people thinking that they are geek & they are the only person here known everything :) . But they are good in talking , We are the people who work with coding all days all time . I’m damn sure we are geeks not them ….

    Have fun coding :)
    Gobi

  11. November 30th, 2010 at 11:29 | #12

    It’s not just the interviewer. This is a common issue. Many developers also try to treat or bend PHP into something like Java. Because PHP is often perceived as inferior language, this is unconsciously compensated with synactic salt and semantic constructs from other environments. This is commonly called “cargo cult programming”. (Another example would be the access modifiers public/private/proctected, which only add hypothetical benefits but add a security appearance to your code.)

    Anyway, it’s important to GET OVER IT. It is an issue in PHP, and you won’t find a company without it. Embrace questionable coding methodologies to fit in, and perform language education cannily.

  12. November 30th, 2010 at 12:10 | #13

    @mario
    “cargo cult programming” a new terms for me.
    For comment about “access modifiers public/private/proctected”, it is debatable. I feel we need to for allowing or not allowing to modify it and how we need to access it as well. Not just for security reason.

  13. November 30th, 2010 at 15:34 | #14

    Facepalm to them! Maybe it’s better look for job on another company.. Or you’ll need to use their PHP-Java version. :P

  14. henk
    November 30th, 2010 at 17:45 | #15

    About your remark that Java copied C++… actually it mostly copied the behavior and feel of Objective-C. The syntax for defining a class, class members and calling those is C++, but the behavior is much more like Objective-C.

  15. Matt
    November 30th, 2010 at 20:23 | #16

    @Thomas
    I think posting about this is fine as long as you don’t name the interviewer or his company. If the interviewer reads this, great. It’s an opportunity to learn from his mistakes.

    Speaking as someone who has interviewed a lot of developers over the years, you need to walk into technical interviews knowing the material inside and out. There’s no excuse for not knowing the answers to the questions you ask. If you’re not sure, don’t ask.

    A good developer will spot an incompetent interviewer very quickly.

  16. foo
    November 30th, 2010 at 21:27 | #17

    super(); ?

  17. Monika
    December 1st, 2010 at 12:08 | #18

    I completely agree with the fact that if you don’t know the answer don’t ask question. I take interviews for my company and before taking any interview I make sure that I know all the concepts before asking any question to candidate.

    What Satya mentioned is very common, because many big companies don’t have expertise people in LAMP. So if anyone from JAVA or Microsoft platform takes interview he/she compares and expects all the answers with his technology area.

    Anyway Satya don’t mind all this,, may be you deserve a better place :)
    also send your profile to my email id.

    • December 1st, 2010 at 13:40 | #19

      Actually I know how things works here. but my only irritation is why they cannot listen me when I was putting my points forwards and telling them convincingly.

  18. December 6th, 2010 at 19:45 | #20

    Hehehe good man, that has to be a crappy place to work if people in charge for technical interview do not even know their answers. Well …. it still could work if they would not insist on their version :)

    chin up, im sure there are better places than this one.

    Cheers

  19. February 7th, 2011 at 15:52 | #21

    A good developer will spot an incompetent interviewer very quickly

  20. March 14th, 2011 at 04:28 | #22

    thank you for this very useful blog hope to see it grow bigger soon

  21. November 7th, 2011 at 15:38 | #23

    You know I do like PHP and I don’t want it to become Java too. Nowadays you should clearly know what do you want to realize thereafter you easily can do it in PHP.

Comments are open for an year period. Please, write here on Facebook page.