Accessing the $age variable using this-> : this « Class « PHP






Accessing the $age variable using this->

 
<?php
class Cat {
    var $age;

    function Cat($new_age){
        $this->age = $new_age;
    }
    function Birthday(  ){

        $this->age++;
    }
}

$fluffy = new Cat(1);
echo "Age is $fluffy->age <br />";
echo "Birthday<br/>";

$fluffy->Birthday(  );
echo "Age is $fluffy->age <br />";
?>
  
  








Related examples in the same category

1.Use this keyword to reference interal properties
2.Use this keyword
3.$this keyword refers to the instance from within the class definition