Accessing the $age variable using this-> : this « Class « PHP
- PHP
- Class
- this
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