Click to See Complete Forum and Search --> : Need help in: OOP in PHP: beginner


pats
12-20-2005, 02:48 AM
Hi
just now i learned to create a classes in php.
after saving the file with extension .inc. where to store the file & how to call that class file in php.

eg:
mynewclass.inc:

class mynewclass{
function(----
------)
{
}
}

calling.php :
how to call the class file here:

pls expain with some egs
so that its wasy to understand for me.

reply
pats

bokeh
12-20-2005, 03:55 AM
Give the included file a php extension; it better for security. If you still want the .inc you could use filename.inc.php You can store your includes anywhere on the server file path that you can access (including non-public directories) or in the includes directory. My example assumes the include is in the same directory as the script calling it.include('mynewclass.inc'); // i'd give this file a .php extension
$variableName = new mynewclass;

Reli4nt
12-21-2005, 07:11 AM
Yep.
The anytime you need it in the script thereafter just do $variableName->functionName()
OOP is great and once you get used to it you'll be moving a lot of your scripts to these very portable classes.