PHP Object Data Type

Object Data Type

Object is a data type that can be either a number, variable even a function. Objects created with the intent to assist programmers who are familiar with OOP (Object Oriented Programming), although the facilities provided OOP PHP is still very limited.
Consider the example below object.php:

class data {
car $name = "John Lennon";
function set_var($name) {
$this->name = $name;
$class = new data;
echo $class->name;$class->set_var("That's not my name");
echo ("<br>$class->name");

In the browser view will look like the image below:
John Lennon
That's not my name
In the program above object.php there is a class named data, then created a data object class data from the data, data on print and out is John Lennon. Class has a method of data set_var name. This method is used to assign values to variable $name. Data object data created from the class of data will have all properties of a class of data, including the methods, so that a type of data object can also contain a method (function). In the above program set_var method on data objects we use to change the value of variable $name to be “That's not my name” and then print.


Post a Comment