By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

storing php5 classes and function

P: n/a
what is the best way to store and call php classes written and
submitted by other developers?

let's say i want to do the following

$obj = new $userclass();
$obj->display($assoc_array);

basically developers will have away to write different "print" method
of given array. How and where would I store their class source fine
and how would I load and use to display?

Thanks!

Dec 22 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Take a look at autoloading.

http://uk2.php.net/autoload

e.g.

function __autoload($class_name) {
require_once $class_name . '.php';
}
Dec 22 '07 #2

P: n/a
function __autoload($class_name) {
require_once $class_name . '.php';
}
One nice thing to notice: an included file can return a value, which may
be an instance. So you could write a class in a file that looks like this:

class WhatEver
{
....
}

return new WhatEver();

And then call that dynamically:

$obj = require($pathToWhatEver);

I use this trick for my unit testing system.
Dec 23 '07 #3

P: n/a
macca schrieb:
Take a look at autoloading.

http://uk2.php.net/autoload

e.g.

function __autoload($class_name) {
require_once $class_name . '.php';
}
Thats the bad way.

Better to use spl_register_autoload() with userdefined autoload
functions. So other developers are also able to use own autoloads.

So long, Ulf

Dec 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.