OOP is a means of structuring programs as "Objects" it stands for Object Oriented Programming.
The concept is that everything is an object, think about it. In real life, everything we give a name, has a border around it. That's how we can differentiate a coffee cup for example from a keyboard. And the keys on the keyboard from the keyboard. We give every different object we see a different name. That way we can tell each other what we are seeing and making use of.
OOP requires a unique kind of mind to understand it, most people can develop the skills however the people who understand OOP are people who are very very technically minded. In my opinion, once you understand OOP you understand how humans perceive the universe we live in.
http://php.net/manual/en/language.oop5.php
			
			
									
						
							Classes php
Re: Classes php
Fighting for peace is declaring war on war. If you want peace be peaceful.
			
						Re: Classes php
They are two different approaches.
I like the example in following SO question: http://stackoverflow.com/questions/7592 ... -and-oo-pr
http://www.virtuosimedia.com/dev/php/pr ... amming-oop
http://ecomputernotes.com/java/what-is- ... ng-in-java
			
			
									
						
										
						I like the example in following SO question: http://stackoverflow.com/questions/7592 ... -and-oo-pr
source:Employing an OOP style has significant advantages over procedural programming, especially as your scale increases. Consider the savings we would receive from OOP in terms of repeated code, flexibility, and maintenance if we also had to add forms for boats, motorcycles, planes, go-karts, ATVs, snowmobiles, etc. Objects and methods are also far easier to test than procedural programming by using unit testing to test results.
http://www.virtuosimedia.com/dev/php/pr ... amming-oop
source:• Procedural Programming
– top down design
– create functions to do small tasks
– communicate by parameters and return values
• Object Oriented Programming
– design and represent objects
– determine relationships between objects
– determine attributes each object has
– determine behaviours each object will respond to
– create objects and send messages to them to use or manipulate their attributes
http://ecomputernotes.com/java/what-is- ... ng-in-java
Re: Classes php
Code: Select all
<?php
class Car {
    public $wheels = 4
    public $topSpeed = 250;
    public $make;
    public $model;
    function __construct($make, $model)
    {
        $this->make = $make;
        $this->model = $model;
    }
    function toString()
    {
        return $this->make . ' ' . $this->model;
    }
}
$civic = new Car('Honda', 'Civic');
echo $civic->toString(); // Honda Civic
echo $civic->topSpeed; // 250   Fighting for peace is declaring war on war. If you want peace be peaceful.
			
						- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Classes php
OOP in JS is completely different. JS is not even a classical OOP language. Rather, JS is Prototype-Based.
The reason why you would use OOP is because it provides a much better structure for very large applications. When you are just working with functions in procedural programming, all of your data has to be "loose" and intermingling with other data. In OOP, you are making little units with your data and attaching the behaviors that can be performed on it. You also can control access. If something in your program is sensitive, you can strictly control what can access it and in what way. There really is nothing similar in procedural programming. OOP is also great with code re-use. In OOP, you don't care or have to care how an object does the work it does. All you have to know is its interface (how to interact with it) and what it returns. This makes OOP classes "black boxes" that you can pick up and drop into any application. Code libraries really exploded when OOP became popular in the early 80's because code re-use works so well with OOP.
I am a big fan of OOP and use it for pretty much everything except the most trivial 10 or 15 line application. EDIT: Well, in JS I am not always rocking the OOP because OOP is so strange there. I try to use the Module Pattern for fairly large JS scripts, but it doesn't always fit.
  EDIT: Well, in JS I am not always rocking the OOP because OOP is so strange there. I try to use the Module Pattern for fairly large JS scripts, but it doesn't always fit.
			
			
									
						
							The reason why you would use OOP is because it provides a much better structure for very large applications. When you are just working with functions in procedural programming, all of your data has to be "loose" and intermingling with other data. In OOP, you are making little units with your data and attaching the behaviors that can be performed on it. You also can control access. If something in your program is sensitive, you can strictly control what can access it and in what way. There really is nothing similar in procedural programming. OOP is also great with code re-use. In OOP, you don't care or have to care how an object does the work it does. All you have to know is its interface (how to interact with it) and what it returns. This makes OOP classes "black boxes" that you can pick up and drop into any application. Code libraries really exploded when OOP became popular in the early 80's because code re-use works so well with OOP.
I am a big fan of OOP and use it for pretty much everything except the most trivial 10 or 15 line application.
 EDIT: Well, in JS I am not always rocking the OOP because OOP is so strange there. I try to use the Module Pattern for fairly large JS scripts, but it doesn't always fit.
  EDIT: Well, in JS I am not always rocking the OOP because OOP is so strange there. I try to use the Module Pattern for fairly large JS scripts, but it doesn't always fit.The indelible lord of tl;dr
			
						Re: Classes php
You're daring to be skeptic about a proven method. A programmer should never limit themselves to one programming language or technique. Otherwise you'll never master any language.Oroton wrote:I don't get why you would use classes in php, seems like more work to do something with out classes.
In saying that it looks very similar to JS
You're working with software that is probably nearly 80% object oriented, why not take the effort to learn how it works. I'd advise you to work with some C#, you can't get any more strictly Object Oriented than that.
Fighting for peace is declaring war on war. If you want peace be peaceful.
			
						
