[TYPO3-dev] call_user_func and sending parameters

Tapio Markula tapio.markula at xetpoint.fi
Wed Aug 15 12:35:46 CEST 2007


Oliver Hader
> Hi Tapio,
> 
> Tapio Markula schrieb:
>> I looked
>> http://fi2.php.net/manual/fi/function.call-user-func-array.php
>>
>>  Object methods may also be invoked statically using this function by
>> passing array($objectname, $methodname) to the function parameter.
>>
>> [...]
>>
>> call_user_func(array($classname, 'say_hello'));
> 
> You posted the link to call_user_func_array() but using call_user_func()
> in your code?!

yes, I meaned funtion call_user_func, which I tried to use
> 
> This example works for dynamic static calls like "myClass:myFunction()".
> You can test it on your environment. If the string 'Constructor called'
> is sent to STDOUT you know that the object was instantiated and thus
> isn't static anymore.
> 
> <?php
> 	class myClass {
> 		var $test = 'test';
> 		function myClass() {
> 			echo "Constructor called\n";
> 		}
> 		function myFunction() {
> 			echo "Hello World\n";
> 		}
> 	}
> 		// Call static:
> 	$className = 'myClass';
> 	call_user_func_array(array($className, 'myFunction'), array());
> 		// Call object:
> 	$myClassObj = new myClass();
> 	$myClassObj->myFunction();
> ?>

I'm not familiar with new class objects - I try always first call 
existing methods using $this->myFunction or tx_myClass::myFunction
from another class file.

Anyway I must use new object using standard Typo3 core functions

			if($this->noContentForSpecialDoktype && $table=='tt_content') {
				$methodName = 'renderDoktype_'.$this->doktype;
				$specialDoktypesObj =& t3lib_div::getUserObj 
('&tx_tmcontentaccess_specialdoktypes','');
				$dblist->HTMLcode .= 
$specialDoktypesObj->$methodName($this->pageRecord);
				}
			if(!($table=='tt_content' && $this->noContentForSpecialDoktype))
				$dblist->generateList();

You might wander, what that does?

For certain page types in Web > Page > Column/Language views the content 
areas will not be rendered, but handled like in TemplaVoila (in fact I 
added into TemplaVoila missing handling of doktype 'spacer' into 
tm_tvpagemodule).




More information about the TYPO3-dev mailing list