Hack Forums
[PHP] Moving from procedural to OOP? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] Moving from procedural to OOP? (/showthread.php?tid=5858036)



Moving from procedural to OOP? - .eXe - Jul 5, 2018

How difficult is it to move from procedural to OOP? I've always coded in proc, and never even touched OOP. Are there any preparation steps I should take? Any pitfalls to look out for?


RE: Moving from procedural to OOP? - Quad - Jul 5, 2018

shouldn't be too difficult if you're good at procedural.

in the simplest cases you will be changing from
PHP Code

<?php 
do_something
($resource, $paramater) 
to
PHP Code

<?php 
$resource
->do_something($paramater); 



RE: Moving from procedural to OOP? - d4rkc4st - Jul 6, 2018

(Jul 5, 2018 12:57 AM)Evil.eXe Wrote:  How difficult is it to move from procedural to OOP? I've always coded in proc, and never even touched OOP. Are there any preparation steps I should take? Any pitfalls to look out for?

There must be tons of tutorials and books out there since PHP became OO. e.g. https :// code.tutsplus.com/ tutorials/object-oriented-php-for-beginners--net-12762


RE: Moving from procedural to OOP? - .eXe - Jul 6, 2018

(Jul 6, 2018 07:02 AM)d4rkc4st Wrote:  There must be tons of tutorials and books out there since PHP became OO. e.g. https :// code.tutsplus.com/ tutorials/object-oriented-php-for-beginners--net-12762

Using PHP in an OOP setting isn't what I asked, it was the best way to move from only using procedural to OOP.


RE: Moving from procedural to OOP? - m0noxide - Jul 6, 2018

Look up the S.O.L.I.D design principles for OOP and that should steer you in the right direction.


RE: Moving from procedural to OOP? - vercenta - Jul 8, 2018

(Jul 6, 2018 07:11 AM)Evil.eXe Wrote:  Using PHP in an OOP setting isn't what I asked, it was the best way to move from only using procedural to OOP.

Just make sole purposes functions for everything and then call it a class, pretty much what OOP is lol.


RE: Moving from procedural to OOP? - Link2 - Jul 9, 2018

Hi,

i wrote a little example for you: gist.github.com/mariusgerum/a32e803e1022956759c4764dad74dec9 (sorry i can't post real links yet, so just copy&paste it into your browser).

As you can see the logic resides in one single place where you actually need it instead of spreading that shit all over your entire codebase.