NYCPHP Meetup

NYPHP.org

[nycphp-talk] How many of you guys are "down" with Java/OO - like programming concepts?

Dan Cech dcech at phpwerx.net
Wed Feb 18 16:43:43 EST 2004


Ok, my formal training was in Java, and I believe that it is definitely 
possible (and with php5 much easier and more efficient) to program php 
in the same way that you program Java.

> I am now learning how to write PHP not necessarily as flat script but as 
> an OO construct, that is, classes, "abstract" classes, "interfaces", 
> Singleton Design Patterns, etc.  and it's really helping me out a lot 
> toward understanding how to come close to implementing it in Java.

I initially took the view that php was a scripting language and attacked 
it from that perspective, but the more I code the closer I get to a 
Java-style approach (ie eliminating the majority of the procedural code 
and encapsulating everything in classes and objects).

> Except for one problem.  The various Java programming and online 
> resources (and offline books I have) basically all inform me that 
> understanding Java from a "scripter's perspective" is flat wrong, 
> because Java is pure OO and involves concepts such as Polymorphism, 
> Encapsulation, Inheritance, even things like Beans and Struts they claim 
> you cannot know as a scripter but as a pure OO programmer.

I think in the current world of php there is room for everyone, from the 
pure procedural 'script' programmer to the OO guru, and everything in 
between.

> So I'm asking the experts among me for advice: should I continue my 
> persuit of PHP from what little OO knowledge I have?  Also, do any of 
> you share a Java background along with PHP and see any symbiosis 
> possible between the two and if even possible that a scripter such as 
> myself could cross over into the OO Universe anytime?

I think it is more than possible, though personally I prefer PHP to 
Java, and for anything web-related I would almost certainly use PHP 
rather than Java, purely because it is so flexible and easy to use.  As 
for crossing over into OO, just take things one step at a time, once you 
grasp the concepts behind OO you will see plenty of situations where you 
could use OO design methods.  For example there are countless situations 
where you can encapsulate functionality into a generic object, then use 
inheritance to specialise that object for your particular needs.

The 'pure-OO' programmers amongst us may frown on this approach, but I 
think in the world of PHP it makes sense.

Dan




More information about the talk mailing list