how to create an object in class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qumar
Forum Commoner
Posts: 29
Joined: Wed Nov 01, 2006 8:20 am

how to create an object in class

Post by qumar »

hi,
i need code for how to create an object in class, give the example.
Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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();
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Re: how to create an object in class

Post 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();
       }
   }
?>
Post Reply