<p>I have a start of a webapp that I wrote without using the Object Oriented features of PHP.</p>

<p>I don't really know if it is worth it to go back and rewrite the parts I have finished. Is object oriented PHP worth rewriting all or part of a decent working app?</p>

[{'answer_id': 57633, 'author': 'GEOCHET', 'author_id': 5640, 'author_profile': 'https://Stackoverflow.com/users/5640', 'pm_score': 2, 'selected': False, 'text': "<p>I wouldn't say it is critical, but if you are going to go much further with the app, I would recommend doing it now while it is not as much of a monumental task. I would say the maintainability of a well written OOP program could far outweigh the up front costs. Especially when you consider that you will be able to refactor much of the code as you go along.</p>\n"}, {'answer_id': 57638, 'author': 'stukelly', 'author_id': 5891, 'author_profile': 'https://Stackoverflow.com/users/5891', 'pm_score': 2, 'selected': False, 'text': '<p>Learning object oriented techinques will be really useful, especially for programming in other languages in the future.</p>\n\n<p>Since you have only just started the application, you could rewrite and improve the parts you have written.  It depends on your deadline.</p>\n'}, {'answer_id': 57646, 'author': 'Jarrett Meyer', 'author_id': 5834, 'author_profile': 'https://Stackoverflow.com/users/5834', 'pm_score': 2, 'selected': False, 'text': '<p>Typical answer: "It depends."</p>\n\n<p>I tend to write the display page as a start-to-finish, &lt; html > to &lt; /html > scripted page. But the things that happen on that page were objects. Kinda like a poor man\'s ASP. While you <em>can</em> have OOP-base output, I alwasy thought it too cumbersome for a task as tedious as dumping data to a browser.</p>\n\n<p>So, business rules and data access were OOP. Presentation was script.</p>\n\n<p>If you have business rules that are <strong>not</strong> OOP, I would seriously consider writing those as objects on two conditions: (1) is "Do you have time/effort/money to do so?" and (2) is "Do you have a good PHP IDE that will make your life easier?" If it works, and changing it means writing in Notepad++, then I would call it done. :-)</p>\n'}, {'answer_id': 57697, 'author': 'Laith', 'author_id': 5961, 'author_profile': 'https://Stackoverflow.com/users/5961', 'pm_score': 5, 'selected': True, 'text': '<p>Given that you have an incomplete app I would say that reworking it into an Object based app will probably be helpful. </p>\n\n<p>One thing to consider is the expected size of the end application. Below a certain complexity Object based may be overkill except for the learning experience.</p>\n\n<p>I started out avoiding Objects like the plague because my initial introduction to them in university classes was terrible. I somewhat recently had to work on a project which was implemented in php objects. making the required changes was much easier than other projects. I have since then worked in the object model frequently and find it very handy for quick creation and easier upkeep.</p>\n'}, {'answer_id': 57829, 'author': 'reefnet_alex', 'author_id': 2745, 'author_profile': 'https://Stackoverflow.com/users/2745', 'pm_score': 4, 'selected': False, 'text': '<p>Just to disagree with the consensus... I would say no in most cases. Not as an academic exercise on commercial code anyway. If it\'s working don\'t re-write it. If you have to go in to change / add bits, then refactor towards OO practices (there are lots of posts on SO about refactoring when you are changing code anyway, and not just for the sake of it). </p>\n\n<p>In practise if you haven\'t done a lot of OOP, then you\'ll want to start small and get a feel for it. </p>\n\n<p>Once you get a handle on the basics, a good beginners guide to Design Patterns (I like the Head First book) is very useful. Most PHP books would teach you OOP fairly poorly. They teach you about inheritance, but usually don\'t teach you about loose coupling and favouring composition over inheritance. A design patterns book will give you a better insight into this. </p>\n\n<p>PHP still has a reputation for not "doing" OO right. I don\'t think this is fair, but is a reflection of the fact that it\'s so easy for people to get started without really grokking OOP. I would go out on a limb and say the majority (ever so slightly - call it 51%) of PHP programmers aren\'t comfortable with OOP. I think it\'s possible to do good OO in PHP, and if you\'re already comfortable with the language it\'s a great way to grow your skills.</p>\n\n<p>EDIT: </p>\n\n<p>Just to add a couple of disclaimers...</p>\n\n<ol>\n<li>My comment about <em>most</em> PHP programmers not being comfortable with OOP wouldn\'t apply to the current SO audience!</li>\n<li>Not suggesting you aren\'t comfortable with OOP, this applies <em>if</em> you\'re not</li>\n</ol>\n'}, {'answer_id': 58376, 'author': 'SeanDowney', 'author_id': 5261, 'author_profile': 'https://Stackoverflow.com/users/5261', 'pm_score': 0, 'selected': False, 'text': "<p>I would say try and go OO just because what you have can be reused much easier than procedural <em>if done right</em> </p>\n\n<p>I will also say that OO is much more organized then procedural. When your at a small scale it's easy to get away with sloppy code OO or not. But when you get to larger projects your procedural must be much more organized and thought out. Where as on some larger projects OO tends to force you to be more organized making things a little easier.</p>\n"}, {'answer_id': 62349, 'author': 'DeeCee', 'author_id': 5895, 'author_profile': 'https://Stackoverflow.com/users/5895', 'pm_score': 0, 'selected': False, 'text': "<p>No, i think if the app is working like it should there's no need to rewrite it.\nPHP isn't really OOP at all. They try hard but sometimes i think even the PHP-Developers dont really understand the sense of OOP. \nIf you wish to learn OOP (which is surely a good idea) try a real OOP-language like Smalltalk to learn the basic concepts. Java is also nice 2 learn the basic, although it isnt fully OOP as well</p>\n"}, {'answer_id': 62424, 'author': 'user6774', 'author_id': 6774, 'author_profile': 'https://Stackoverflow.com/users/6774', 'pm_score': 1, 'selected': False, 'text': "<p>There are two possibilities: either your app is a one-off that just has to work right now and will never be touched, adapted, expanded or modified, <strong>or else</strong> your app is the beginning of something that you will keep working with and using over a long time.</p>\n\n<p>If the former, don't break perfectly usable code.  You have better things to do with your time.</p>\n\n<p>If the latter, you have to bear in mind an important fact about PHP, which is this: <strong>poorly written PHP is a nightmare to maintain.</strong>  Not as bad as poorly written Perl -- because what is? -- but bad enough that sooner or later you will feel a strong urge to steal a time machine, travel back to the moment you wrote the code you now find yourself maintaining, and stab yourself in the eye socket with an icepick.</p>\n\n<p>So if you're going to be maintaining this code over time, take the time to do it right.  That means: some kind of templating system, no PHP tags embedded inside HTML, separate files for separate functionality, and <strong>classes classes classes</strong>!</p>\n\n<p>Your eye sockets will thank you.</p>\n"}, {'answer_id': 62478, 'author': 'RobbieGee', 'author_id': 6752, 'author_profile': 'https://Stackoverflow.com/users/6752', 'pm_score': 0, 'selected': False, 'text': "<p>I'd like to reiterate the other answers here. It depends upon size of application and how much you'd like to learn about OOP. I'd be careful of learning OOP by using PHP though.</p>\n\n<p>As for how much PHP <strong>is</strong> object oriented... PHP4 had some OOP elements slapped onto it, PHP5 is better but it's not baked into the language. PHP works both ways, and personally I like that you can choose.</p>\n"}, {'answer_id': 7279484, 'author': 'diyism', 'author_id': 264181, 'author_profile': 'https://Stackoverflow.com/users/264181', 'pm_score': 0, 'selected': False, 'text': "<p>In my mind, we phper can thorouly throw away the concept of Object(class instance), we only need Array and Mode Class:</p>\n\n<p>All arrays in initial mode support any array function as it's method:</p>\n\n<pre><code>&lt;?php\n$array1-&gt;array_flip(this);\n?&gt;\n</code></pre>\n\n<p>Use <code>-&gt;mode()</code> to validate the minimal data set, and then switch mode class:</p>\n\n<pre><code>&lt;?php\n$array1-&gt;mode('class1', $success);\n?&gt;\n</code></pre>\n\n<p>Any mode class has no <code>-&gt;construct()</code> in it, but has <code>-&gt;validate()</code> to validate the minimal data set.</p>\n\n<p>The array in a mode still could use array function as its method, but after using any of them the array will be switched back into basic array mode,\nand we need to use <code>-&gt;mode('class1', $success);</code> to switch mode back.</p>\n\n<p>The radical thought is data-centric programming, we need separate the data(array) and the activity(class method).</p>\n\n<p>We could modify PHP engine, to get rid of parts of OO(object oriented), and support Mode Class, we could call it MyPHP.</p>\n\n<p>For example:\n<code>$array_man1</code> could be set into two modes:<code>cls_normal_man</code> and <code>cls_crazy_man</code>:</p>\n\n<pre><code>&lt;?php\n$array_man1-&gt;mode('cls_normal_man')-&gt;normal_method1()-&gt;mode('cls_crazy_man')-&gt;crazy_method1();\n?&gt;\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/57622', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/673/']