You would do well to read up on classes and instances.
Code: Select all
//instantiate our class
$objDemo = new Demo();
Create an
instance of class Demo, we'll call this
instance $objDemo
Code: Select all
//assign what the name variable is in our class
$objDemo->name = 'Bob';
Assign a value of 'Bob' to the name attribute of the $objDemo
instance
Code: Select all
//to access the method, we have to use the same var name as our instantiated class
$objDemo->sayHello();
Call the sayHello() method of the $objDemo
instance
We've taken our basic class definition and created an object in the variable $objDemo using that class. This object, is an instance of class Demo. We can create other instances of the Demo object
Code: Select all
$objDemo2 = new Demo();
$objDemo2->name = 'Rita';
$objDemo3 = new Demo();
$objDemo3->name = 'Sue';
Now we have three instances of the Demo object, each in its own variable with it's own name attribute set differently, and each is totally independent. Even though they're all created using the same class definition, they are now separate instances.
Create an
instance of class Test, we'll call this
instance $objDemoX. While methods and properties in the Test class are inherited from those in the Demo class, they are methods and attributes from the class definition... not from any already instantiated objects of the Demo class. It doesn't know or care that Rita, Sue or Bob already exits as instances of the Demo class. The name property is not set, because the Demo class definition doesn't have a default.
Doesn't change any of $objDemo, $objDemo2 or $objDemo3 instances.