OOP?
Re: OOP?
Very basically, OOP is a way to structure and easily maintain your code.
Please check out my CodeCanyon items.
Re: OOP?
Basically, yes. There is nothing that you can do with classes that you can not also do with simple functions. It's more of an organisation thing than anything else, for example, everything to do with working with a user can be in a class called "user".JelvinJS7 wrote:I don't get how that works though. If you Take out the class keyword/brackets, and remove all the "public", "private", "protected"s, etc, then you get the same thing, don't you
Re: OOP?
I think I'm sort of getting it… a few things:
1) How do I simply echo something with a class? Would I have to do something like this?
1) How do I simply echo something with a class? Would I have to do something like this?
<?php class Class{ public $string = "This is a string In a class that I will echo out later. "; public $string.= "I'm quite redundant..."; public function functio_n(){ Echo "anger from not being allowed to have a function named \"function\"!"; //insert a bunch of things to be done that aren't relevant at all } } ?>
<?php echo Class::$string; ?>2) Can someone make a kind of in-depth example of how to use it, in a way that would be used for a real project (and not a way that a teacher would use)?
Re: OOP?
This is a good tutorial http://marketplace.tutsplus.com/item/-o ... -14/122845
I purchased the last chapters (the MySQL DB class)
I purchased the last chapters (the MySQL DB class)
Re: OOP?
I've been thinking about this and whether I agree. I agree that OOP is mainly an organisational thing. However, what about inheritance, you cannot do it with regular procedural code. Sure, that is used mostly for organisation too, but I still don't know whether I completely agree about your statement.jacek wrote:Basically, yes. There is nothing that you can do with classes that you can not also do with simple functions. It's more of an organisation thing than anything else, for example, everything to do with working with a user can be in a class called "user".
@ JelvinJS7: you might want to dig a little deeper into the basics of OOP. You're setting an object property (in OOP variables are called properties) and a public method (in OOP functions are called methods) which echoes a string. However you're echo'ing that method again, while calling it as a static. If you didn't understand what I just said: it only confirms my suspicion that you should first look into the basics (what is OOP, what is public, private, protected, static etc.).
Re: OOP?
Well inheritance has no place in procedural style code since everythign is in global scope. So you can just call any functions that exist in what ever function you are working on.libeco wrote:I agree that OOP is mainly an organisational thing. However, what about inheritance, you cannot do it with regular procedural code.
what I really mean thought, was there is no product you can make with OOP that you can;t with the old way So you can make a forum using loads of functions but you can also do it using a few classes of methods, and both ways are perfectly fine as long as you keep it neat
Re: OOP?
Well I Have been trying to look Into it. I understand the difference private, public, and protected. I can't really remember what static does and I can declare a class, and then use it. Hypothetically speaking, I can extend a class (haven't tried it yet… but I know what to do ).libeco wrote: JelvinJS7: you might want to dig a little deeper into the basics of OOP. You're setting an object property (in OOP variables are called properties) and a public method (in OOP functions are called methods) which echoes a string. However you're echo'ing that method again, while calling it as a static. If you didn't understand what I just said: it only confirms my suspicion that you should first look into the basics (what is OOP, what is public, private, protected, static etc.).
My example was me asking. B/c in Jacek's videos, he did this:
class Example { public function test_public(){ echo "public"; } //... } //… Example::test_public()And I'm asking if I have to declare a function just to echo something, or (In this case), make a variable in the class, then echo it outside the class?
@Jacek: in one of your project tutorial series...things, if possible, can you also implement Classes?
Re: OOP?
The problem with OOP in php is next to some languages the Object orientated version is strange. The idea is to load only what you need, and yet by default php has a large library of functions to load for you...
I would suggest you look into the basics of an OOP based programming languages (e.g. Python) as once you have the basic idea of how they work it's rather easy to understand the concept, and implement within PHP. Now what do I mean by basics? Look into using Python's math functions. All you really need. Once you understand that concept, watch the "classes" tutorial Jack has made, and you should have a solid ground to start on.
I would suggest you look into the basics of an OOP based programming languages (e.g. Python) as once you have the basic idea of how they work it's rather easy to understand the concept, and implement within PHP. Now what do I mean by basics? Look into using Python's math functions. All you really need. Once you understand that concept, watch the "classes" tutorial Jack has made, and you should have a solid ground to start on.
Re: OOP?
Well, I would say you should not be doing either really. If you defined the output inside the logic part of your code it all gets confusing. It depends on the situation, but I would normally have the method (what functions are called in classes) return the information only (like an array or usernames) and then output that how you want to on the actual page.JelvinJS7 wrote:And I'm asking if I have to declare a function just to echo something, or (In this case), make a variable in the class, then echo it outside the class?
I don't really know the formal explanation, but a static method in a class is the same as a normal function not in a class. so you don't need an instance of the object to call it.JelvinJS7 wrote:I can't really remember what static does
I will try, but I have been trying to think of something that would work well as an example for some time. Also it just makes it so much harder to explain things because of all the awkward terminology.JelvinJS7 wrote:@Jacek: in one of your project tutorial series...things, if possible, can you also implement Classes?
Re: OOP?
I agree it will be quite difficult. If people don't understand what they're using, implementing it makes no sense. So you would first need to make videos covering basic implementation and terminology of OOP with PHP, and then you would be able to make a series in which you implement OOP.
Otherwise I think people will get lost very easily.
Otherwise I think people will get lost very easily.
Please check out my CodeCanyon items.
Re: OOP?
jacek wrote:Maybe it would be a good idea to do a oop version and a normal version of the same thing ?
That's indeed a good idea. But i think it can also be a bit redundant.
Re: OOP?
Sorry to bring this up again, but I'd just been doing some research via videos, and I'm finally starting to get it! I wanted to share that.
So this quest had still been going on, and when [insert user here] posted a question about the developer API, I saw that classes were used, so I decided to watch. Then today I watched a couple of phpacademy's videos for thenewboston (alex's one video on his channel was really not helpful!). I reached an epiphany of understand! so this is what I think would be helpful:
So one reason oop would be helpful would be like, for example, would be like how in Facebook there's an option to see "mutual friendship" between you and a friend. So somewhere there's a user class that fetches all user info (name, the many likes, friends, etc) by using a construct function that's fed some ID. Then on the "mutual" page, it's something like
I also get the purpose of protected and private methods/properties—to use them within another function in the class that will be used publicly, but not otherwise. (still don't get static, but there's time).
Just thought I'd share. Am I on the right track
So this quest had still been going on, and when [insert user here] posted a question about the developer API, I saw that classes were used, so I decided to watch. Then today I watched a couple of phpacademy's videos for thenewboston (alex's one video on his channel was really not helpful!). I reached an epiphany of understand! so this is what I think would be helpful:
So one reason oop would be helpful would be like, for example, would be like how in Facebook there's an option to see "mutual friendship" between you and a friend. So somewhere there's a user class that fetches all user info (name, the many likes, friends, etc) by using a construct function that's fed some ID. Then on the "mutual" page, it's something like
$loggedin_user = new User($_SESSION['id']); $users_friend = new User($_GET[{other user's id}]);Then compares the two variables.
I also get the purpose of protected and private methods/properties—to use them within another function in the class that will be used publicly, but not otherwise. (still don't get static, but there's time).
Just thought I'd share. Am I on the right track
Re: OOP?
Static methods in classes are basically the same as functions.JelvinJS7 wrote:(still don't get static, but there's time).
Re: OOP?
Well you can still make them private and use sell:: to refer to other methods in that class.
But they work in the same way when you call them.
But they work in the same way when you call them.