4-Object Oriented in PHP PDF
4-Object Oriented in PHP PDF
4-Object Oriented in PHP PDF
Understanding Object-Oriented
Programming
Object-oriented programming is a style of
coding that allows developers to group similar
tasks into classes. This helps keep code
following the tenet dont repeat yourself
(DRY) and easy-to-maintain.
var_dump($obj);
?>
Example:
http://localhost/meeting12/myclasswithmethod.php
<?php
class MyClass
{
public $prop1 = "I'm a class property!"; //property
public function setProperty($newval) //class set
{
$this->prop1 = $newval;
}
public function getProperty() //class get
{
return $this->prop1 . "<br />";
}
}
$obj = new MyClass;
echo $obj->prop1;
?>
THANKS