tags:

views:

122

answers:

5

I have a ready made PHP class. Now how can I use that class or implement it in my page. How would I go about doing this?

A: 
$classInstance = new ClassName();
$classInstance->methodName();

some basics here

seengee
+1  A: 

You can use your class by calling it in the following ways:

$var = new ClassName;
$var -> methods();
$var -> publicVars;
Sam152
+7  A: 

Your question is a bit vague, but you first need to have that class "visible" from your script, which is generally done using require_once to "include" the file containing your class.

Then, you can instanciate your class :

$my_object = new MyClass();

And, then, you can call its methods :

$my_object->myMethod($param);


Don't hesitate to go through the related pages in the PHP manual : Classes and Objects ; it'll cover some basic grounds, which will help you a lot ;-)

Pascal MARTIN
+1  A: 

In your php page, you need to include the class:

<?php require_once("path/to/your/class/ClassName.class.php") ?>

And then you need to initialise it:

$classVariableName = new ClassName;

$classVariableName->foo('bar');

Hope that helps :-)

Jamie
+2  A: 

For the details you will have to provide the actual class or, even better, check the documentation that hopefully came with this class. For a general tutorial on how to use classes in PHP you might want to take a look at the official documentation

Horst Gutmann