SyncViews Posted January 16, 2008 Share Posted January 16, 2008 I really can't see a reason to use OOP. Seeing as a php script runs just once I can't see a purpose of objects (eg if I was useing c++ and making CnC I would use objects for say buildings as there is more than one and each needs it's own vars) Why bother useing OOP for say bbcode when I could just a have a function that takes a string, turns the BB code into html then echos it. I'm sure there is a reason for useing OOP for these things but I reeally can't see any use in php... Quote Link to comment Share on other sites More sharing options...
Fyorl Posted January 16, 2008 Share Posted January 16, 2008 It's down to preference really. I never used to use OOP but since I've programmed more and more in PHP I've found uses for it. It's nice to have certain things all contained in state-aware functions. Also, objects can technically persist over sessions. You don't have to use OOP though. Some people just prefer procedural programming while others see things interacting as objects. If what you're doing now works for you then don't worry about OOP. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted January 16, 2008 Share Posted January 16, 2008 Well to start with I personally use Oops in pages when I want to reuse something... The classical Oops concept why re-invent the wheel.. well this is the same thing.. I could have multiple classes layered over each other. Quote Link to comment Share on other sites More sharing options...
SyncViews Posted January 16, 2008 Author Share Posted January 16, 2008 Ive just been useing functions contained in my functions.php file for stuff I reuse just like I have a functions.js for all the java script functions I want to reuse. Quote Link to comment Share on other sites More sharing options...
predator Posted January 17, 2008 Share Posted January 17, 2008 it is up to you how you want to run at the end of the day but OOP is becoming a bigger thing so it is better programming practise to get into these days Quote Link to comment Share on other sites More sharing options...
Fyorl Posted January 17, 2008 Share Posted January 17, 2008 I don't think OOP is becoming bigger. It was always big. Ever since C++ arrived and people switched to it over C due to it allowing OOP. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted January 19, 2008 Share Posted January 19, 2008 OOP gives you a level of re usability the procedural does not. I mean if I used plain functions I would have to use pass the database resource to every function call or even worst, make them global. Using OOP keeps you away from learning bad habits. Quote Link to comment Share on other sites More sharing options...
taith Posted January 20, 2008 Share Posted January 20, 2008 personally... i see no uses for server sided OOP... in client sided i can see all kinds of uses... autoformatting, timers, spawners(games), etc... but on client side, your always running top to bottom(no timers) and all formatting can be done by flatfile functions... Quote Link to comment Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 But you can serialize objects and have them persist over sessions. Also, like Liquid Fire said, OOP has lots of benefits in terms of data structure and interaction. It's also much better for collaborative projects as it provides encapsulation. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted January 20, 2008 Share Posted January 20, 2008 I think that people who do not think that extensive use of OOP in programs would be useful does not have sufficient knowledge about it. Quote Link to comment Share on other sites More sharing options...
SyncViews Posted January 21, 2008 Author Share Posted January 21, 2008 I still don't really see a use of it in php. In c++ I used oop for stuff like making an ini praser as I want to have multiple files open at once. But then thats because I need to keep the ini file open between loops so that the data is updated all the time before being saved on exit. so "start program -> prase files(like 10) -> START LOOP -> get user input -> update ini data strutures -> CONTIUE TO LOOP UNTILL EXIT -> save files -> exit" Php doesn't loop like that as user input requires a new page so it ends up as "prase file A-> echo data -> prase file B -> send page to client " then the next page when the user presses submit "build fileA-> save file -> build fileB -> save file -> end" Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted January 21, 2008 Share Posted January 21, 2008 OOP is also good to group functions that the are common to each other a perform actions on the same from of data. I use mostly OOP in PHP because it make my code a lot clean to use. If you don't see a point to it then don't use it, bust there is no reason not to use it. Quote Link to comment Share on other sites More sharing options...
448191 Posted January 22, 2008 Share Posted January 22, 2008 I don't think I really have to emphasize my position on this, but... Quote Link to comment Share on other sites More sharing options...
kts Posted January 23, 2008 Share Posted January 23, 2008 OOP is seeming to be more of a standard for larger projects, because its easier to manage and cuts down a little bit on code from functions which in a large project adds up. Anything can be done in anyway, its just on average OOP is more efficient. Quote Link to comment Share on other sites More sharing options...
lcaesars Posted January 31, 2008 Share Posted January 31, 2008 OOP is also good to group functions that the are common to each other a perform actions on the same from of data. I'm a newbie in OOP but it's always a question in my mind. It sounds great to have a group of functions together. But what about the optimized coding and RAM usage? I mean when we include a large class file to a project, there may be some unnecessary methods depending on the project. Isn't it a bad programming practice? Quote Link to comment Share on other sites More sharing options...
Fyorl Posted January 31, 2008 Share Posted January 31, 2008 It would be better practice to only write methods that you use... Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted January 31, 2008 Share Posted January 31, 2008 OOP is also good to group functions that the are common to each other a perform actions on the same from of data. I'm a newbie in OOP but it's always a question in my mind. It sounds great to have a group of functions together. But what about the optimized coding and RAM usage? I mean when we include a large class file to a project, there may be some unnecessary methods depending on the project. Isn't it a bad programming practice? The only way to make sure the functions you include for a page are all needed it to have each function is a seperate and then include each file that has a function you need, That does not seems optimized. How would you optimized it? Quote Link to comment Share on other sites More sharing options...
Guardian-Mage Posted February 4, 2008 Share Posted February 4, 2008 OOP is almost required when programming large and complex software such as forum software (Which I am currently doing). OOP can save time, and teaches you more about the language. Many employers would rather hire somebody familiar with OOP as well. Quote Link to comment Share on other sites More sharing options...
vadim88 Posted February 4, 2008 Share Posted February 4, 2008 can someone show me a simple diffrence between code written in PHP and in OOP? and an advanced code written in PHP and OOP i wanna see the diffrence between them. thanks. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 4, 2008 Share Posted February 4, 2008 can someone show me a simple diffrence between code written in PHP and in OOP? and an advanced code written in PHP and OOP i wanna see the diffrence between them. thanks. OOP is not a language so we cannot show you the difference between OOP and PHP. Quote Link to comment Share on other sites More sharing options...
Guardian-Mage Posted February 4, 2008 Share Posted February 4, 2008 OOP is part of PHP, it extends the functionality of PHP, and can help make complicated tasks easier Quote Link to comment Share on other sites More sharing options...
Fyorl Posted February 4, 2008 Share Posted February 4, 2008 OOP stands for Object Oriented (should be Orientated really but that's a different argument) Programming and as such is just a way of writing your code (as opposed to Procedural Programming). Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted February 5, 2008 Share Posted February 5, 2008 can someone show me a simple diffrence between code written in PHP and in OOP? and an advanced code written in PHP and OOP i wanna see the diffrence between them. thanks. I think you mean procedural and OOP. I could show you an example of a php framework that i built OO Programming but i would never waste the time building is in purely procedural. showing you simple examples is not going to work because simple example looks like procedural is just as good but as thing grow you then begin to see the issues or maintain and scalability. Quote Link to comment Share on other sites More sharing options...
Stooney Posted February 8, 2008 Share Posted February 8, 2008 OOP is also good to group functions that the are common to each other a perform actions on the same from of data. I'm a newbie in OOP but it's always a question in my mind. It sounds great to have a group of functions together. But what about the optimized coding and RAM usage? I mean when we include a large class file to a project, there may be some unnecessary methods depending on the project. Isn't it a bad programming practice? There's a couple things that help here. You can have php autoload a file containing your class when it is called upon, otherwise it will not be loaded. Also, you can have one generic class with a lot of functionality, then you can have smaller more specific classes that inherit the generic classes methods/variables, then customize the it. So basically you can write one class, and stem from it many classes without rewriting all the code per class. You can look at it like a mold. Say you have a carver that's starts from a square block and they need to carve 10 human figures. They could use a mold (assuming they're carving plastic for some reason) to start with a generic human shape and then go from there, or they can just start with the square block and waste time. (Maybe not the greatest analogy every thought of but I think it works) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.