1: Introduction To Object Oriented PHP Programming 2: Simple Explanation Of The MVC Model 3: Create Classes In Object Oriented PHP 4: What Are Scopes In Object Oriented PHP Programming 5: Properties And Methods In Object Oriented PHP 6: MAGIC METHODS - Construct And Deconstruct Methods 7: Delete Objects In Object Oriented PHP 8: How To Use The toString Method 9: Static Properties And Methods In Object Oriented PHP 10: Initialise Object Properties In Object Oriented PHP - How to pass a parameter in a Constructor method inside a class 11: Our First Exercise Using Object Oriented PHP, Basic Calculator 12: Connect To A Database Using MySQLi 13: How To Connect To A Database Using PDO PHP 14: How To Query A Database Using PDO PHP
* If an object $object points to a variable, like name,
* echo $object ->name;
* the program will fail.
*/
?>
</body>
</html>
</!DOCTYPE>
====================================
====Filename ====================== includes/parentclass1.inc.php =================================== <?php class ParentClass{ //Properties and Methods go here public $name = "Hey there!"; } ?>
<!------------------------------------------- /* Youtube Video https://youtu.be/w8jVNr-dDlM * VID Lec#5 * index5.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php include 'includes/newclass5.inc.php'; ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php $object = new NewClass; $object2 = new NewClass; /* * Want to access a property inside an object. */ $object->setNewProperty("This is a user Daniel."); echo $object->getProperty()."<br>"; $object2->setNewProperty("This is a user called Jon."); echo $object2->getProperty()."<br>"; ?> </body> </html> </!DOCTYPE> <!------------------------------------------- * newclass5.inc.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php class NewClass { //Properties and Methods go here public $data = "I am a property"; public function setNewProperty($newdata){ $this->data = $newdata; } public function getProperty(){ return $this->data; } } ?>
_____VID #6_____________________
6: MAGIC METHODS - Construct And Deconstruct Methods
<!------------------------------------------- /* Youtube Video https://youtu.be/w8jVNr-dDlM * VID Lec#6 * index6.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php include 'includes/newclass6.inc.php'; ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php $object = new NewClass; $object2 = new NewClass; /* Want to access a property inside an object.*/ echo $object->getProperty()."<br>"; ?> </body> </html> </!DOCTYPE> <!------------------------------------------- * newclass6.inc.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php class NewClass { //Properties and Methods go here public $data = "I am a property"; public function __construct(){ echo "This class has been instantiated."."<br>"; } public function setNewProperty($newdata){ $this->data = $newdata; } public function getProperty(){ return $this->data; } public function __destruct(){ echo "This is the end of the class!"."<br>"; } } ?>
_____VID #7_____________________
7: Delete Objects In Object Oriented PHP
<!------------------------------------------- /* Youtube Video https://youtu.be/w8jVNr-dDlM * VID Lec#7 * index7.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php include 'includes/newclass7.inc.php'; ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php $object = new NewClass; unset($object); echo $object->getProperty()."<br>"; ?> </body> </html> </!DOCTYPE> <!------------------------------------------- * newclass7.inc.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php class NewClass { //Properties and Methods go here public $data = "I am a property"; public function __construct(){ echo "This class has been instantiated."."<br>"; } public function setNewProperty($newdata){ $this->data = $newdata; } public function getProperty(){ return $this->data; } public function __destruct(){ echo "This is the end of the class!"."<br>"; } }
?>
_____VID #8_____________________
8: How To Use The toString Method
<!------------------------------------------- /* Youtube Video https://youtu.be/w8jVNr-dDlM * VID Lec#8 * index8.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php include 'includes/newclass8.inc.php'; ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php $object = new NewClass; echo $object."<br>"; ?> </body> </html> </!DOCTYPE> <!------------------------------------------- * newclass8.inc.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php class NewClass { //Properties and Methods go here public $data = "I am a property"; public $error = "This is a class called.. ".__CLASS__."..!"; public function __construct(){ echo "This class has been instantiated."."<br>"; } public function __toString(){ echo "toString Method:"; return $this->error; } public function setNewProperty($newdata){ $this->data = $newdata; } public function getProperty(){ return $this->data; } public function __destruct(){ echo "This is the end of the class!"."<br>"; } } ?>
_____VID #9____________________
9: Static Properties And Methods In Object Oriented PHP_
<!------------------------------------------- /* Youtube Video https://youtu.be/w8jVNr-dDlM * VID Lec#9 * index9.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php include 'includes/newclass9.inc.php'; ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php echo NewClass::staticMethod(); ?> </body> </html> </!DOCTYPE> <!------------------------------------------- * newclass9.inc.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php class NewClass { //Properties and Methods go here public $data = "I am a property"; public $error = "This is a class called.. ".__CLASS__."..!"; public static $static = 0; public function __construct(){ echo "This class has been instantiated."."<br>"; } public function __toString(){ echo "toString Method:"; return $this->error; } public static function staticMethod(){ return self::$static + 2; } public function setNewProperty($newdata){ $this->data = $newdata; } public function getProperty(){ return $this->data; } public function __destruct(){ echo "This is the end of the class!"."<br>"; } } ?>
_____VID #10____________________
10: Initialise Object Properties In Object Oriented PHP
How to pass a parameter in a Constructor method inside a class_
<!------------------------------------------- /* Youtube Video https://youtu.be/w8jVNr-dDlM * VID Lec#10 * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php include 'includes/newclass10.inc.php'; ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php $users = new Users('john','Doe','Blond','Brown'); echo "Fullname: ".$users ->fullname().'<br>'; echo "Profile".$users ->profile(); ?> </body> </html> </!DOCTYPE> <!------------------------------------------- * newclass10.inc.php * PHP Programming|OOP PHP Tutorial | Learn OOP PHP */ --------------------------------------------> <?php class Users { //Properties and Methods go here public $first; public $last; public $hairColor; public $eyeColor; public function __construct($first, $last, $hairColor, $eyeColor){ $this->first = $first; $this->last = $last; $this->hairColor = $hairColor; $this->eyeColor = $eyeColor; } public function fullname(){ return $this->first. " ".$this->last; } public function profile(){ return $this->hairColor." and ".$this->eyeColor; } public function __destruct(){ } } ?> ========================== output ========================== Fullname: john Doe ProfileBlond and Brown ==========================