Page 1 of 1

how to create an object in class

Posted: Wed Nov 08, 2006 3:00 am
by qumar
hi,
i need code for how to create an object in class, give the example.
Thanks.

Posted: Wed Nov 08, 2006 3:05 am
by John Cartwright
I'm not exactly sure what you are asking :? Perhaps have a read in the manual about very basic oop principles

As for creating an actual object, use the new keyword ie..

Code: Select all

$object = new ClassNameGoesHere();

Re: how to create an object in class

Posted: Thu Nov 09, 2006 12:17 am
by christian_phpbeginner
qumar wrote:hi,
i need code for how to create an object in class, give the example.
Thanks.
How to create object in class ? What do you mean ? For example:

You can create an object within a class in the constructor class:

Code: Select all

<?php
   require_once ('class.Foo.php');
   class Bar {
       private $_foo;
       
       public function __construct () {
           $this->_foo = new Foo();
       }
   }
?>