r/PHPhelp • u/Sweedtea • 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!
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
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
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
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
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
Dec 14 '21
https://phpenthusiast.com/ best for oop in php. Buy the book if you can .Best book for OOP in Php.
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.