Re: How to call a function from $classname

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



André Pletschette wrote:
Hi,

What do I have to do to call a function from $classname?

Like: $classname->test( );


<?php
// does $classname contain a name of a class? e.g:

class Test
{
	function doIt() { echo "done it!\n"; }
}

$className = "Test";
$t = new $className;
$t->doIt();

// also look at the functions
// call_user_func() and call_user_func_array(),
// e.g:

call_user_func( array($className,"doIt") );

?>

BTW: I'm only using double-quotes when its really needed
because it makes testing the code in a linux shell 100 times
easier (when compared to using single-quotes).

AGAIN BTW: nobody understood your question so far because
'$classname->test();' is valid php syntax! (it just assumes
that $classname 'is' an object, not a string)

happy now? ;-)



Thankyou, André


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux