I'd like to call an external function (one defined outside a class) as a
method of a class. Is this possible? If I want a generic Dump method that
outputs the Methods and Properties of a class then I'd rather not code it
into each and every class.
I've included the JavaScript code that does what I want but of course
JavaScript isn't really OO and my understanding is it just assigns the code
of the function to the variable and then evaluates it.
ANY suggestions greatly appreciated etc. etc.
JavaScript doesn't really have classes but you can emulate them "sort of" as
follows.
function newClass ()
{
//the "method"
this.myMethod = newClass_myMethod;
}
function newClass_method()
{
return "I'm the output from myMethod";
}
instanceOf = new newClass();
//this would output the alert box;
alert(instanceOf.myMethod());
Is this sort of thing possible in PHP?
I'd like to accomplish the following:
class newClass
{
function newClass($name)
{
$this->name = $name;
}
$this->DumpMethods = some sort of reference to an external function...
}
function dumpObjectMethods($obj)
{
//loop through the array returned by get_class_methods($obj) and output
them
}
So if the class is instantiated.
$foo = new newClass("theName");
//is there a way to make the following work????
echo $foo->DumpMethods();
Hi Wade,
Why don't you use a generic class which contains this method and all new
classes are extensions of the generic class?
JOn
class dumpable {
function dumpObjectMethods($obj) {
//loop through the array...
}
}
class newClass extends dumpable {
function newClass($name) {
$this->name = $name;
}
}
now you can:
$x = new newClass('bob');
$x->dumpObjectMethods($something);
though for what you ask, i'd guess the dumpObjectMethods shouldn't
take arguments, but use $this when looping out the methods.
Bob
--
B. Johannessen sip:b...@h.db.org
b...@db.org tel:+47 33314030
http://db.org/ fax:+47 33313846
E9D4 D43C A6AE 80D8 98C8 878F A288 AC53 230E 1658 mob:+47 97152009