views:

129

answers:

3

code is in a static class in an external file eg. /home/test/public_html/fg2/templatecode/RecordMOD/photoslide.mod

how do I load this into my script on demand, and be able to call its functions ?

I am a novice at php , so please explain your code.

help is appreciated.

Jer

+1  A: 

As long as the included code is wrapped in PHP blocks, you can use include or require for this.

Like so:

include( '/home/test/public_html/fg2/templatecode/RecordMOD/photoslide.mod' );

You can then do whatever you wish, call functions, etc.

Jacob Relkin
+1  A: 

To use the variables or classes (static or otherwise) they need to be loaded before being used. Typically you would make a call like:

<?php
require('/home/test/public_html/fg2/templatecode/RecordMOD/photoslide.mod');
?>

You can also do without the parentheses:

<?php
require '/home/test/public_html/fg2/templatecode/RecordMOD/photoslide.mod';
?>

...somewhere at the top of your code.

It would be good to review include(), require(), include_once(), and require_once()

artlung
A: 

Might be too advanced right now, but PHP supports an autoloader. You would still use the include/require code that is mentioned above. But instead that code would live inside a special function that will be called anytime you access a class/interface that hasn't already been loaded. This will allow you to see what is being requested and dynamically load files on demand.

Including/requiring a few files is fine. Once you get into a large site with tons of files it will be easier to use the autoloader then explicitly writing an include/require line for each. Plus you will save memory by not loading things you aren't using.

Autoloader Docs, thats the easy version. The better implimentation is with spl_autoload_register.

CrashRoX