skaterdav85 Posted May 6, 2009 Share Posted May 6, 2009 whats the standard in php development? do alot of web developers do OOP in php, or not? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2009 Share Posted May 6, 2009 Yeah, a lot of professional developers use OOP techniques. If you have a class that does a certain task, it's easy to move it around to other software projects and not have to re-code a bunch of stuff. It's also easier to make changes to the underlying algorithms without having to change all the code that uses them. In the biggest application I'm working on now, I'm using 8 custom classes that I built for various things, and another few that I got online (PDF generation, etc). The classes I built are things to handle config settings, caching data, database work, user sessions, stuff like that, generic things that I can take and use on other projects without needing to change anything.Other things don't really need an entire class. I wanted to simplify handling uploaded files, but instead of an entire class to do that, all that was necessary was a single function. Resizing an image is the same thing, an entire class to handle images might be nice to build, but I wanted a generic image resizing method and all that was required was a single function. Link to comment Share on other sites More sharing options...
skaterdav85 Posted May 6, 2009 Author Share Posted May 6, 2009 Yeah, a lot of professional developers use OOP techniques. If you have a class that does a certain task, it's easy to move it around to other software projects and not have to re-code a bunch of stuff. It's also easier to make changes to the underlying algorithms without having to change all the code that uses them. In the biggest application I'm working on now, I'm using 8 custom classes that I built for various things, and another few that I got online (PDF generation, etc). The classes I built are things to handle config settings, caching data, database work, user sessions, stuff like that, generic things that I can take and use on other projects without needing to change anything.Other things don't really need an entire class. I wanted to simplify handling uploaded files, but instead of an entire class to do that, all that was necessary was a single function. Resizing an image is the same thing, an entire class to handle images might be nice to build, but I wanted a generic image resizing method and all that was required was a single function.how long have you done php development? did it take you a long time to learn oop in php? ... Ive been doing alot of php in my class at school, like creating logins and disseminating rest/soap web services, but it hasnt been object oriented, so i felt like i should learn oop in php. any recommendations as to go about learning it? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2009 Share Posted May 6, 2009 I learned PHP on my own while I was in college, I've been using it for around 7 years or so. It didn't take me a long time to understand the OOP concepts because I was using C++ all through college. OOP is a general topic, it's not related to PHP specifically. You might start with a general book to learn OOP concepts in general:http://oreilly.com/catalog/9780596008673/and then a PHP-specific one, to learn how PHP does it:http://oreilly.com/catalog/9781593270773/ Link to comment Share on other sites More sharing options...
skaterdav85 Posted June 17, 2009 Author Share Posted June 17, 2009 I learned PHP on my own while I was in college, I've been using it for around 7 years or so. It didn't take me a long time to understand the OOP concepts because I was using C++ all through college. OOP is a general topic, it's not related to PHP specifically. You might start with a general book to learn OOP concepts in general:http://oreilly.com/catalog/9780596008673/and then a PHP-specific one, to learn how PHP does it:http://oreilly.com/catalog/9781593270773/ have you read that 2nd book? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 17, 2009 Share Posted June 17, 2009 No I haven't. Link to comment Share on other sites More sharing options...
skaterdav85 Posted August 20, 2009 Author Share Posted August 20, 2009 So i've been reading some stuff on OOP in PHP, and ive been told its not good to put html or css in your classes. What if you are pulling data from a database and you are going to loop through the results of the query and output them in a table...Would you put the loop in your view page and just do the query in a method? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 20, 2009 Share Posted August 20, 2009 Right, the class should just return the data, in an array or something. The page that uses the data would be responsible for formatting it for display. Link to comment Share on other sites More sharing options...
skaterdav85 Posted August 21, 2009 Author Share Posted August 21, 2009 I understand the syntactical basics of how to create objects, but I'm not sure how to group certain things together, or what is the best way to create an object. Say you were creating a blog site, would you separate each module into its own object...and have a blog object to insert and read out entries, an object for the login system, an object for a poll module etc? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 21, 2009 Share Posted August 21, 2009 Yeah something like that. I have a session class that I use for handling all of the login and session-related things, I've got a database class for any database work, etc. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.