A Class with a Constructor : Constructor Class PHP

 
<?php
 class Item {
   var $name;

   function Item( $name="item") {
     $this->name = $name;
   }

   function setName( $n) {
     $this->name = $n;
   }

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

 $item = new Item("5");
 print $item->getName ();
?>
  
  

A Basic PHP 4 Class : Class Definition Class PHP

 
<?php
    class myPHP4Class {
        var $my_variable;
        function my_method($param) {
            echo "my_method($param)!n";
            echo "my variable is: ";
            echo "{$this->my_variable}n";
        }
    }

     $myinstance = new myPHP4Class();
     $anotherinstance = new myPHP4Class();
?>