Jump to content

Object Oriented in PHP5


Spaceman-Spiff

When you start a new project in php5, would you code object oriented?  

26 members have voted

  1. 1. When you start a new project in php5, would you code object oriented?

    • Yes, entirely OO
      7
    • Partially OO
      17
    • No OO (Procedural)
      2
    • I don't code in PHP
      0


Recommended Posts

We're starting a new project at work, the team only consists of 2 programmer (me and the other guy). The other guy's background is Java and PHP5. My background is more varied from Basic, Pascal, VB, Java, C++, C#, PHP 3, 4, and now starting 5. I have never really coded anything in fully OO in PHP5, aside from modifying/tweaking codes. So far all of my past PHP projects have been procedural. It's the fastest way to code for me.

 

Now, for this project, my co-worker wants everything coded in pure OO. No global variables/declarations at all. It's a decent-sized project with 2-3 months development time.

 

I don't mind to start learning about OO in PHP5, but my main concern is coding in OO style may mean longer development time. Another concern is the code may not perform as fast as it would if coded procedurally. His main argument is coding in OO will make the project more extensible.

 

From my past experiences with Java and C#, OO codes tends to be longer (more total lines of code), thus also take longer to code. It is more "secure" and the code looks prettier (sometimes), is it always worth it?

 

I have read the other topic about this. I do want feedback on this more specific matter.

Link to comment
Share on other sites

It has nothing to do with security or looking pretty.  I would say the most fundamental concept is re-usability.  That is what Object Oriented Programming great.  It also follows a logic that is easy to understand.  I also don't think that you should always use OOP.  Sometimes it is easier and faster to do small little tasks procedurally.  But if you plan to build anything extensive, such as an ecommerce site or CMS, OOP just makes more sense.

Link to comment
Share on other sites

I have to agree with jcombs_31. Mostly i program in oop style cos many classes i use pretty often such as logon classes and formvalidation. because i have them in classes it saved me tons of time creating new cms systems. But some stuff is simply easier to place as a function because you want to use it a lot and not just for one class.

 

So pretty much keep in mind what you are going to build and if something will be usable in the future might as well spend a little more time on it now so you can re-use for future projects. but dont overdo it. php 5 has better oop support compared to php 4 but php != java. and lets keep it that way

Link to comment
Share on other sites

The person who voted 'entirely OOP' is a big fat liar :P

 

It is impossible to code entirely OO with PHP. In fact, I'd even say it is impossible to code entirely OO in any language that isn't fully OO itself. That includes any language with primitive types, including C++, C, C# and Java. You can code entirely OO in Smalltalk and Ruby.

Link to comment
Share on other sites

I'm sure when they say 'entirely OOP' they mean as much as possible. :) Of course you will need to initiate the classes in the first place.

I selected 'entirely OOP'.

 

I can't stand to see a script without OOP now.

Link to comment
Share on other sites

  • 2 weeks later...

I started typing a response, but I ended up posting my thoughts on OOP here: http://nick.stinemates.org/wordpress/

 

This is about as procedural as my code gets (I dont expect it to make sense, its just an example):

 

<?php

require_once("src/php/com/cm/qa/ws/factory/RequestFactory.class.php");
require_once("src/php/com/cm/qa/ws/factory/FileNotFoundException.class.php");
require_once("src/php/com/cm/qa/ws/command/CommandDispatcher.class.php");
require_once("src/php/com/cm/qa/ws/validator/Validator.interface.php");
require_once("src/php/com/cm/qa/ws/validator/ExpectedResultsValidator.class.php");

$r = RequestFactory::getInstance()->getFactory("GetMessageLog.xml");

print "<pre>";

while($request = $r->getRequest()) {

try {
$validator = new ExpectedResultsValidator();
        $c = new CommandDispatcher($request->getURL());
        $call = $request->getCall();
        print "Executing $call \n";
        $response = $c->dispatch($request);
        
        $expected = $request->getExpectedResults();
        $report = $validator->validate($response, $expected);
while ($myresults = $report->next()) {
	if($myresults->getState()) {
		print $myresults->getSearch() . " - PASS \n";
	} else {
		print $myresults->getSearch() . " - FAIL \n";

	}

}


} catch (FileNotFoundException$e) {

}

}

Link to comment
Share on other sites

  • 2 months later...

i use PHP 4 OO cos most of our systems are legacey, there not compleetly oo like JAVA like you want yours i can see teh benifits of that but yeh that sounds best. there is alot more possible with PHP5, i think the MVC will be hard to impliment if you make it entirley, i can see things getting tricky if you use compleetly OOP

Link to comment
Share on other sites

I started typing a response, but I ended up posting my thoughts on OOP here: http://nick.stinemates.org/wordpress/

 

This is about as procedural as my code gets (I dont expect it to make sense, its just an example):

 

<?php

require_once("src/php/com/cm/qa/ws/factory/RequestFactory.class.php");
require_once("src/php/com/cm/qa/ws/factory/FileNotFoundException.class.php");
require_once("src/php/com/cm/qa/ws/command/CommandDispatcher.class.php");
require_once("src/php/com/cm/qa/ws/validator/Validator.interface.php");
require_once("src/php/com/cm/qa/ws/validator/ExpectedResultsValidator.class.php");

$r = RequestFactory::getInstance()->getFactory("GetMessageLog.xml");

print "<pre>";

while($request = $r->getRequest()) {

try {
$validator = new ExpectedResultsValidator();
        $c = new CommandDispatcher($request->getURL());
        $call = $request->getCall();
        print "Executing $call \n";
        $response = $c->dispatch($request);
        
        $expected = $request->getExpectedResults();
        $report = $validator->validate($response, $expected);
while ($myresults = $report->next()) {
	if($myresults->getState()) {
		print $myresults->getSearch() . " - PASS \n";
	} else {
		print $myresults->getSearch() . " - FAIL \n";

	}

}


} catch (FileNotFoundException$e) {

}

}

 

 

on your website you say "I find the lack of documentation of Python + ncurses somewhat exciting"

 

i bet you also like to be dominated, sorry to break it to you buddy, its not actualy your code, just like english dosent belong to you its imposed on you because its made by somonee else before you.

 

making things complex is like walking backwards

 

why writwe in perl when you can write it in php

 

not if they offered me a million £ i would never say "I find the lack of documentation of Python + ncurses somewhat exciting"

 

i bet you `are best freind with ur boss and never come in l8 ?

 

sorry i dont mean to judge u m8, its just touched a nerv for some reason you may be a great person.

Link to comment
Share on other sites

  • 3 weeks later...

 

on your website you say "I find the lack of documentation of Python + ncurses somewhat exciting"

 

 

Let's be fair. I also said I found it somewhat irritating. Of course, the engineer in me loves to explore and create something useful. Which I did. I wrote a Listbox implementation which you can see on the page.

 

The irritating part is, that's about as far as I can go without reading related material in implementation. I can play around, sure, but really what I am left with is to actually read real world ncurses implementations, which is not trivial.

 

The funny thing is, you and I believe in the same principles, they just seem to be lost a little in translation. I hate making things needlessly complex. I truly believe in creating simple, basic things. The process of leveraging these simple, basic things to create complexities which are easy to understand is almost artistic and (at least to me) beautiful.

Link to comment
Share on other sites

I think the main virtue of PHP5 is that you can integrate the best of both worlds. I think it's better to have a parser object than a "text_functions.php" file. I also think it's pointless to start creating classes for every data type, and try to avoid languages like Ruby that take this to the extreme.

 

But that's just my opinion; that's how I like to work.

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.