Create a new class and create an instance then use its property and method : Objects « Class « PHP






Create a new class and create an instance then use its property and method

 
<?php
class Dog
{
  var $name;

  function bark()
  {
    print "Woof!";
  }
}

$pooch = new Dog;

$pooch -> name = "new name";

print $pooch -> name . " says ";

$pooch -> bark();

?>
  
  








Related examples in the same category

1.Comparing Objects with == and ===
2.Object Initialization
3.Object Overloading
4.Object Properties
5.Object Type Information
6.Objects Within Objects
7.Creating a new object and assigning it to a variable