3. Objects in PHP can’t be declared literally An instance must be created from a class. class myClass{var $attribute1;var $attribute2; function method1() { // Code here return $something; } function method2() { // Code here }} $myObject = new myClass();
4. What can it do? Organizes variables, functions, and information Shorten code to improve readability Add in an additional layer of functionality
5. Essentially creates a new variable User defined Can create as many of this type as desired Can access any attribute or method of the object Allows the creation of constructors which execute upon instantiation. $myObject2 = new myClass();$myObject3 = new myClass();$myObject4 = new myClass(); // Attributes $myObject->attribute1 = ‘X'; $myObject->attribute2 = ‘Y'; // Methods $returned = $myObject->method1(); $myObject->method2();
6. Why use it? Increases ease of organizing longer projects Re-use of classes and variables Cuts back on repetitious typing of code Better organization of code Speeds up writing process Easier Maintenance