Procedural or OOP

OK, I am a newbie to PHP.

I can make basic CRUD, login/logout, sessions, cookies, little ajax etc.

I like the Procedural method. I am trying to learn OOP but till now everything went above the head.

Comments please :confused:

Sorry for the silly post though :frowning:

1 Like

If you are trying to figure out OOP PHP by reading about it, you might have a problem with everything going right over your head, because it involves a totally different way of thinking about coding web applications. Whether you prefer video tutorials, or written tutorials, try working through a course in OOP that starts right at the beginning, and don’t move on from one stage until you are comfortable with its concepts. The operative word here is working. You need to actually DO, not read, in order to get the hang of it. And maybe you will have to go through the course several times (picking up more each time), but that’s okay.

If you are a Premium member here, there are quite a number of books and video courses on PHP, some of which would be suitable for your needs. Or Jeffrey Way has a good tutorial explaining the basics of OOP with examples on his tutorial site, Laracasts.

6 Likes

For me, having a use for a technique is a key to learning about it.

One example I had was a method of extracting data from a specific type of binary data file - it was quite easy to write a load of procedural functions to parse the structure, extract a record and decode it, but that meant having loads of pointers and arrays and so on passing backwards and forwards, and my calling code has to retain them all, which to me is almost as bad as using global variables. By implementing a class, all the internal stuff can be within that class and the calling code only creates a new object, calls the open method (which opens the file and decodes the index structure) and then it’s just ready to read a record. When I call read(), all I get back is the formatted data or ā€œnot foundā€.

I’m sure there’s a lot more to OOP than my example above, but the main point was really as @webmachine said, actually writing something will probably teach you more than a lot of reading.

2 Likes

I agree wholeheartedly because just gradually moved all my procedural functions, globals etc to a very simple class and it is so much easier,

The application was to:

  • open a webpage
  • parse for a specific XLS URL
  • download the XLS spreadsheet
  • convert to XLS to CVS
  • convert CVS to database
  • send results to a log table

Each class method returned Boolean success and maybe proceed to next step in the class method.

edit
Currently stuck on automating the process using a cron job :frowning:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.