/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /********************** Class Example **********************/ class Car{ //Inconsistency with access modifiers var $tire_count = 4; public $door_count = 2; function num_of_tires(){ //You need to explicitely use $ to assign variables but then don't use them for reference return $string . "<br />"; } } $my_car = new Car(); echo $my_car->tire_count . " :: " . $my_car->door_count . "<br />"; echo $my_car->num_of_tires(); /********************** Global Variable Example **********************/ //No use of var or public $tires = 4; $doors = 2; echo $tires . " :: " . $doors . "<br />"; //echo $this->$cat; //Reference looks ugly $reference =& $tires; echo "Reference before: " . $reference . " || "; $tires = 2; echo "Reference after: " . $reference; ?>
Comments
