submitted by: Guest

PHP: object declaration

declare an object in php. This example also shows how to pass a value to the object when created.


code snippet:
<?php
// declare an object class with member properties and methods
class Vegetable {

    var 
$edible;
    var 
$color;

    
//A funtion with the same name as the class behaves as a constructor
    
function Vegetable$edible$color="green" ) {
        
$this->edible $edible;
        
$this->color $color;
    }

    function 
is_edible() {
        return 
$this->edible;
    }

    function 
what_color() {
        return 
$this->color;
    }
    
}
?>