r/PHPhelp • • Dec 14 '21

Solved The easiest way to learn Object Oriented Php?

Do anyone know any good guides or videos explaining how to start with object-oriented Php?

Thanks!

11 Upvotes

26 comments sorted by

6

u/HolyGonzo Dec 14 '21 edited Dec 14 '21

I wrote a couple of articles a long while ago to specifically introduce new programmers to OOP with PHP and explain how it works without getting too lost in technical jargon:

https://www.experts-exchange.com/articles/2626/Beginning-Object-Oriented-Programming-in-PHP.html

https://www.experts-exchange.com/articles/2631/Advanced-Object-Oriented-Programming-in-PHP.html

There have been new concepts and techniques added since the time I wrote these, but these aren't intended to cover everything - just to get you comfy and make it all easy to understand.

2

u/Sweedtea Dec 15 '21

Thank you very much!

2

u/golfgimp Dec 14 '21

Thank you for sharing this. I found it very easy to understand.

1

u/Kokium Dec 14 '21

I had read the two articles. Good stuff. But I think that you have an error in the second article, in the "Accesors and mutators" example. The brackets in $this->name()

1

u/HolyGonzo Dec 14 '21

Ha - you're right. You're the first person to notice that.

1

u/HolyGonzo Dec 14 '21

Okay - I fixed the typo and kicked off the review process to make it live whenever the next editor gets around to it. Thanks for noticing that!

1

u/Glavobolja Jun 20 '23

ThreeLeggedMan, i see what you did there ;)
Jokes aside great read.

1

u/akseptans Feb 10 '24

Hey, just read both of your articles and they were fun and easy to understand, thanks! I'll be recommending them to other new programmers who'd want to learn about OOP too :)

6

u/gordonv Dec 14 '21 edited Dec 14 '21

Learn:

Programming 101

  • variables

  • arrays

  • key pairs

  • programming with functions

  • global variables


Programming Level 200

  • Storing lists of lists. Arrays of Arrays.

  • JSON (This expands out of PHP, but is extremely useful, as it's a universal standard)

  • Objects in PHP (Just variables, not code, to store JSON.

  • script blocks. Storing code in variables. (This an intro to an abstract idea. It makes sense in computers and math, but not in real life.)


Programming Level 300

  • classes

  • learn public and private scoped variables

  • treating objects as individual instances

  • treating functions like properties in an object

  • learn construct / destruct

  • writing specific functions for your specific object type

  • overloading and sharing functions

2

u/gordonv Dec 14 '21

Object oriented programming is very verbose. There is a lot of organization. It's tedious. But it's well organized.

1

u/gordonv Dec 14 '21

In general, if you want to learn the overall theory of basic memory management, take r/cs50.

It's worth it. It teaches you computing. Then programming. YHou start thinking in a structured manner with your programming after this course.

1

u/Sweedtea Dec 15 '21

Thank you everyone for your answers! You guys are amazing

1

u/HolyGonzo Dec 17 '21

Don't forget to the the question and add the Solved flair. :)

1

u/Sweedtea Dec 17 '21

Oopsies, Thanks haha, first-timer in this subreddit here :)

8

u/dabenu Dec 14 '21

What's your baseline here? Do you have any experience with OOP? Do you have any experience with PHP?

3

u/fz-09 Dec 14 '21

This is the question.

OOP principles and design patterns aren't drastically different in PHP than any other language so as long as you know basic PHP syntax, this is more of an OOP question than a PHP question.

That being said, I really enjoyed this book but I wouldn't dive too far into different design patterns until you learn basic OOP principles like classes, objects, variable scope, constructors, destructors, etc.

Good luck OP! Feel free to DM me if you have any questions.

2

u/[deleted] Dec 14 '21

You'll be best trying to use a well established library to start learning. Maybe replace your mysqli connections with doctrine orm models & repos or making an API call with guzzle.

Even have a mess with the DateTime class from PHP itself, loads of OOP methods to play with

2

u/judahnator Dec 14 '21

Going into this project keep this in mind.

In procedural programming, which is the vast majority of what you have done so far, you are telling the computer “do x with y data.”

In object oriented programming, the entire point is “represent y data in x way.”

That’s it. That’s the difference. That’s the whole shebang.

Don’t get caught up in design patterns and whatnot. Get a good grasp on the various kinds of object inheritance, the difference between static vs self, scoping, all that jazz. You got this.

1

u/PonchoVire Dec 14 '21

Reading existing code is probably a good start, but some libraries are advanced and mature and you may not understand everything.

I usually prefer reading existing code over watching some tutorials, it gives you a good hint about how people are using it, and not how it is theoretically described in some courses.

1

u/shohan13579 Dec 14 '21

Give yourself a project first.

1

u/bluesoul Dec 14 '21

I like Laracasts' series on OOP. It helped make it click for me, coming from C and function-oriented PHP.

1

u/tomdob1 Dec 14 '21

Symfonycasts tutorial on OOP PHP was amazing for me

1

u/rjmfc Dec 15 '21

The biggest thing that helped me understand OOP in php was learning a statically-typed object-oriented language. (C# in my case but I imagine Java is just as good).

1

u/[deleted] Dec 14 '21

https://phpenthusiast.com/ best for oop in php. Buy the book if you can .Best book for OOP in Php.