[TYPO3-dev] call_user_func and sending parameters

Oliver Hader oh at inpublica.de
Tue Aug 14 18:33:08 CEST 2007


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?!

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();
?>


olly
-- 
Oliver Hader
http://inpublica.de/




More information about the TYPO3-dev mailing list