<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>
HTML code for linking to this page:
PHP Function Reference -> Users Code Examples / Notes - > Class Constructor: