eaglelegend Posted May 25, 2008 Share Posted May 25, 2008 What is it o.O?... someone make a mistake on the forums "OOP" XD Link to comment https://forums.phpfreaks.com/topic/107228-oop/ Share on other sites More sharing options...
Darklink Posted May 25, 2008 Share Posted May 25, 2008 OOP stands for Object Orientated Programming. To put it basically, an object is something you can make more than one instance of. You would create a class, then set a number of functions and variables inside. Once you have the functions and variables set up, you can use them to create an object. Use a person for example. A persons functions would be, walk, sit down, eat, talk, etc. And the variables would be something like, mood, hair colour, fatigue, etc. When you created the class, you can set them to variables so you can make more than one person. Here's how OOP would look: <?php // Our person class class person { var $mood = 'happy'; var $haircolour = 'brown'; var $fatigue = 0; function walk($type='forward') { // Make the person walk } function sleep($time=300) { // Make the person sleep } } ?> And this is how you an instantiate an object: <?php $person1 = new person(); // Person 1 $person2 = new person(); // Person 2 $person1->walk(); // Make person 1 walk forward $person2->sleep(500); // Make person 2 sleep for 500 minutes? ?> Does this make it clear? There is more to OOP than what I've said though. For instance, changing the objects values: <?php //... Object start var $fatigue = 100; function sleep($length=300) { $this->fatigue = $this->fatigue - $length; if ( $this->fatigue < 1 ) { $this->fatigue = 0; } } //... Object end ?> Link to comment https://forums.phpfreaks.com/topic/107228-oop/#findComment-549806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.