Jump to content

Object Oriented PHP....is it necessary????


Recommended Posts

Hey guys,

I have just learned the PHP and i can say that i can make php based websites now easily, in fact i have made couple of them with myself. So procedural php is not a big deal for me now.

 

However I saw there is much hype for making applications Object Oriented, and they say if you want to become a professional programmer then you must learn Object Oriented style of programming. Now that sounds good as Object Oriented style has got appreciation from all over the internet.

 

The problem with me is i have learned PHP language only and that also from "PHP for dummies" which focuses on procedure oriented.

Now i want to learn Object Oriented PHP and I was reading George Schlossnagle's Advanced PHP Programming and made it to 100'th page but am not able to grasp the OO style yet.

 

Now what i want to ask from you guys is, whether it is necessary to learn Object Oriented PHP? if yes

Will you guys please suggest me some books from where i can get the whole OO concept and use it in PHP ?

Link to comment
https://forums.phpfreaks.com/topic/231247-object-oriented-phpis-it-necessary/
Share on other sites

Books are always nice, building things on your own from simple tutorials and the php manual is all you need. When you read a book you are picking up somebody elses style, you'll want to form you own.

 

OOP is necessary depending on what your script does, how advance it is, if you need a MCV system(model control view), etc.

 

I personally finding OOP much easier than prior php standards. Hell, I'd even use it for small scripts.

 

OOP helps use with the DRY process, DONT REPEAT YOURSELF, oop makes it so objects can be created, passed through other objects, stored into arrays, and be passed around the whole entire website without needing to create the same code for each page.

You'll have to establish for yourself if it's necessary for what you want to do, read up on the manual, look at your books style, and build from there. 

I'm no expert by any means, that's just my two cents.

@OP It's not necessary to learn OOP but it's a nice asset, because like you said, more and more companies are asking for it.

 

if you need a MCV system

 

You don't need OO to write MVC

 

OOP helps use with the DRY process

 

And you can't apply DRY to procedural?

"Dry process" and "MCV" neither of them have been heard by me ever before, so will you guys please elaborate them a bit.

 

I know it is not necessary to learn OO programming skills as far as PHP is concerned but what my plan is to develop websites on my own for some creative ideas that i have in my mind. I am sure if i will build them they will get loads of response...now to build them i don't wanna hire any developer and all i want to do it myself. And I won't mind if it takes a month to learn that before i put my hands on my own project.

 

That's why i asked whether it is necessary to learn OO because someone said that if you wanna build complex websites then you have to learn OO style of programming otherwise the whole code will look like a mess after sometime when you would like add something.

 

I have tried to learn Object oriented PHP from manual and i digested the concept of class, object, functions etc. yet also i don't know why it looks to me that procedural is good and the other one is looking a bit confusing to me?????

DRY (Don't Repeat Yourself) is pretty much what it says, if you have a piece of code that repeats, wrap it in a function. An explanation of MVC can be found at: http://www.phpfreaks.com/forums/index.php?topic=327837.msg1543224#msg1543224

Quoting Larry Ulman from php 5 advanced

 

"You can have a long, happy, and viable programming career without OOP. However you might have a more productive, easier and lucrative career using it."

 

Thanks for suggesting the book....BTW as i mentioned i only know PHP so I need a book which can teach OO based PHP right from the scratch. So should i give it thumbs-up to this.????

Thanks for suggesting the book....BTW as i mentioned i only know PHP so I need a book which can teach OO based PHP right from the scratch. So should i give it thumbs-up to this.????

 

I'm still in baby steps with PHP and I was only quoting Larry to help answer your question. Is OOP necessary?

 

As for books do some research, I'm in my 50's so add that to different personality types and I can almost bet that your learning style is different from mine.

You're not going to be able to master OOP by simply reading 100 pages from a book.  The bulk of OOP is about design, which pros often argue about as there is hardly ever a 'correct' answer to design questions.  Instead, design is largely an exercise in balancing many different criteria, which depend on the individual project.

 

As far as a book goes, the best one for PHP-specific OOP is Matt Zandstra's PHP 5: Objects, Patterns, and Practice (http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X/ref=sr_1_1?ie=UTF8&qid=1300723561&sr=8-1).  With that said, it's certainly not the only valuable resource on the subject, and surely cannot be considered complete.  This is a broad subject, one with different approaches and styles.

You're not going to be able to master OOP by simply reading 100 pages from a book.  The bulk of OOP is about design, which pros often argue about as there is hardly ever a 'correct' answer to design questions.  Instead, design is largely an exercise in balancing many different criteria, which depend on the individual project.

 

As far as a book goes, the best one for PHP-specific OOP is Matt Zandstra's PHP 5: Objects, Patterns, and Practice (http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X/ref=sr_1_1?ie=UTF8&qid=1300723561&sr=8-1).  With that said, it's certainly not the only valuable resource on the subject, and surely cannot be considered complete.  This is a broad subject, one with different approaches and styles.

 

I agree with you that there are several answers and design patterns to solve any problem, and each programmer will give answers to the question in its own way.

But as far my case is concerned i have came up fresh from PHP's procedural, Now when i try to make PHP application regarding to any problem the only answers that come up in my mind is through procedural way of programming. And i guess it is because i have learned it as a procedural only and OO styles are not fed in my mind yet as effectively as the former ones.

 

Checking the manual doesn't gives you much about it as it is full of 'foo' & 'bar', The books that i have downloaded have same information that i have already read in PHP for dummies. So i was just trying catch how did you guys learned Object Oriented ?

It seems that Object Oriented syntax is not a problem for me at all, what i want to learn is the concept of OO and how do i think any problem in object's point of view ?

Since then, I've been reading the blogs, tutorials, and watching screencasts of other developers.

 

That's how i guess I learned the procedural way of PHP, and I was able to write scripts in a matter of 7 days only. But as i said above I wanted to become a real professional in PHP so I thought OO is necessary for that to happen.

BTW i have downloaded both the books(one that is mentioned by you and one of larry ulman mentioned above) and i am giving a read to the one you suggested. Let's see how much I can grasp the concept of OOP from that book.

I started with the book I linked to above.  Then, I got the Gang of Four's book, which is essentially the foundational book on the subject.  Since then, I've been reading the blogs, tutorials, and watching screencasts of other developers.

 

nightslayer, the book of zandstra is the good one right, because the quote above implies that you started, left it unfinished and moved to another. Sorry for asking, but i am going to buy a book on oop ::) And i know there is a complete topic dedicated to this, but for some reason I think you are someone that knows this ::)

No, I bought it, read through it, re-read it multiple times, then bought the Gang of Four book to deepen my understanding and see more patterns.  The Zandstra book is, IMO, the perfect place to start if you're mainly familiar with PHP and want to learn OOP.  But it's certainly not a complete picture of OOP. 

 

The Gang of Four book is essential, IMO, as it explains all of the basic patterns, including those that Zandstra doesn't touch.  For those that he does examine, the GoF book often shows some interesting variations.  This only illustrates the basic premise behind patterns - they're abstract solutions, and need to be modified to fit a particular problem.  That said, I don't think the GoF book is ideal as the first step.  The Zandstra book shines in that regard, as everything is in PHP.  It's comfortable.

 

Blogs and tutorials are good for supplemental learning, but only if they come from a good source.  There are more bad tutorials than good, and the only way to separate the good from the crap is to have a basic understanding of the subject.  That's why I don't recommend those sources initially.  It's too easy to get suckered by bad material.  For the free OOP stuff, I tend to stick with C# and Java developers since those languages are focused on OOP, and only the big names (Scott Guthrie, Scott Hanselman, Phil Haack, Jon Galloway, Martin Fowler (even though he's not necessarily a Java guy), etc.).  That way, I know I'm getting the right information.

 

Finally, I consider myself barely competent with OOP.  I know and understand the basics, but I have so much more to learn - enterprise patterns, domain-driven design, test-driven development, etc.  While they're not all topics that are necessarily exclusive to OOP, there's still a ton to learn.

No, I bought it, read through it, re-read it multiple times, then bought the Gang of Four book to deepen my understanding and see more patterns.  The Zandstra book is, IMO, the perfect place to start if you're mainly familiar with PHP and want to learn OOP.  But it's certainly not a complete picture of OOP. 

 

The Gang of Four book is essential, IMO, as it explains all of the basic patterns, including those that Zandstra doesn't touch.  For those that he does examine, the GoF book often shows some interesting variations.  This only illustrates the basic premise behind patterns - they're abstract solutions, and need to be modified to fit a particular problem.  That said, I don't think the GoF book is ideal as the first step.  The Zandstra book shines in that regard, as everything is in PHP.  It's comfortable.

 

Blogs and tutorials are good for supplemental learning, but only if they come from a good source.  There are more bad tutorials than good, and the only way to separate the good from the crap is to have a basic understanding of the subject.  That's why I don't recommend those sources initially.  It's too easy to get suckered by bad material.  For the free OOP stuff, I tend to stick with C# and Java developers since those languages are focused on OOP, and only the big names (Scott Guthrie, Scott Hanselman, Phil Haack, Jon Galloway, Martin Fowler (even though he's not necessarily a Java guy), etc.).  That way, I know I'm getting the right information.

 

Finally, I consider myself barely competent with OOP.  I know and understand the basics, but I have so much more to learn - enterprise patterns, domain-driven design, test-driven development, etc.  While they're not all topics that are necessarily exclusive to OOP, there's still a ton to learn.

 

Thanks m8! I will buy them both ::) and start with zandstra. I am still learning php procedural style, but it's always good i think to have more books ::) Cheers!

Hey aabid,

  Did you read the oop section of the php manual?  I think you need to really understand the mechanics of php oop really well before taking on design patterns, and it's possible that trying to kill two birds with one stone is not the best approach. 

No, I bought it, read through it, re-read it multiple times, then bought the Gang of Four book to deepen my understanding and see more patterns.  The Zandstra book is, IMO, the perfect place to start if you're mainly familiar with PHP and want to learn OOP.  But it's certainly not a complete picture of OOP.

 

Ya I think it is necessary to read Gand of Four cause I am zandstra's book and the author also has mentioned about it and said some good works. But for now I will continue with zandstra's as it is long 600 page book and after all it meets my requirements as it is in PHP.

After going through it I will go for GoF...:)

BTW Nightslyr, Do you have anymore books to suggest as I am hungry to learn it right from the core to the top.....;)

Hey aabid,

  Did you read the oop section of the php manual?  I think you need to really understand the mechanics of php oop really well before taking on design patterns, and it's possible that trying to kill two birds with one stone is not the best approach.

 

Ya i have already gone through PHP manual and didn't understood much from there because and I think they assume that you have a good knowledge of OOP with other languages and you only want to go catch the grasp of how PHP works in OOP.

That's why I thought it is much better to prefer any reference which can teach me OOP right from the scratch and also through PHP. I have bought the zandstra's book as suggested above and having a read of it. Although I haven't reached to the section which is dedicated to OOP in that but I think its a good one to start with.

No, I bought it, read through it, re-read it multiple times, then bought the Gang of Four book to deepen my understanding and see more patterns.  The Zandstra book is, IMO, the perfect place to start if you're mainly familiar with PHP and want to learn OOP.  But it's certainly not a complete picture of OOP.

 

Ya I think it is necessary to read Gand of Four cause I am zandstra's book and the author also has mentioned about it and said some good works. But for now I will continue with zandstra's as it is long 600 page book and after all it meets my requirements as it is in PHP.

After going through it I will go for GoF...:)

BTW Nightslyr, Do you have anymore books to suggest as I am hungry to learn it right from the core to the top.....;)

 

http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420/ref=sr_1_7?s=books&ie=UTF8&qid=1300793706&sr=1-7

http://www.amazon.com/Domain-Driven-Design-Complexity-Software-DOMAIN-DRIVEN/dp/B002VLOJOY/ref=sr_1_24?s=books&ie=UTF8&qid=1300793862&sr=1-24

http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627/ref=sr_1_3?s=books&ie=UTF8&qid=1300793887&sr=1-3

http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670/ref=sr_1_1?s=books&ie=UTF8&qid=1300793981&sr=1-1

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.