PHP – Classes – Objects
La classe è un contenitore per variabili e funzioni, ad esempio ‘class Car’ contiene variabili e funzioni, è un buon modo per raggruppare cose che funzionano insieme.
An object is a data type which stores data and information on how to process that data.
In PHP, an object must be explicitly declared.
First we must declare a class of object. For this, we use the class keyword. A class is a structure that can contain properties and methods.
We then define the data type in the object class, and then we use the data type in instances of that class.
<?php class Car // first you HAVE TO declare the object { var $color; function Car($color="green") { $this->color = $color; } function what_color() { return $this->color; } } ?>