Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

Class with a Constructor in php

Sun Oct 26, 2008 11:27 pm

Code:
<html>
<head>
<title>A Class with a Constructor</title>
</head>
<body>
<?php
class first_class{
    var
$name;
    function
first_class( $n="default name" ){
        
$this->name = $n;
    }
    function
sayHello(){
        print
"my name is $this->name<BR>";
    }
}
$obj1 = new first_class("object 1");
$obj2 = new first_class("object 2");

$obj1->sayHello();
$obj2->sayHello();

?>
</body>
</html>




Post a reply
  Related Posts  to : Class with a Constructor in php
 class with constructor parameter     -  
 Using a Constructor in jsp     -  
 Copy Constructor     -  
 What Are Constructor Methods?     -  
 using of String constructor     -  
 cannot find symbol constructor     -  
 Define class helper class to check the method existance     -  
 java abstract class,concrete class and interface     -  
 relationship between the Canvas class and the Graphics class     -  
 Define class inside another class C++     -  

Topic Tags

PHP OOP