Reply to Re: [PHP] How to call a function from $classname

Your name:

Reply:


Posted by Jochem Maas on 03/15/05 18:06

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é
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация