A Class with Public Properties : public « Class « PHP






A Class with Public Properties

 
<?php
 class item {
   var $name;
   var $code;
   var $productString;

   function Item( $name="item", $code=0 ) {
     $this->name = $name;
     $this->code = $code;
    $this->setName( $name );
 }

 function getProductString () {
   return $this->productString;
  }

  function setName( $n ) {
    $this->name = $n;
    $this->productString = $this->name." ".$this->code;
  }

  function getName () {
    return $this->name;
  }
 }

 $item = new Item ("A", 5);
 print $item->getProductString ();

 ?>
  
  








Related examples in the same category

1.Use public properties directly
2.Public fields
3.public method
4.Using Class Visibility Operators