note 34474 modified in function.call-user-func by vrana

From: Date: Tue, 17 Aug 2004 14:53:15 +0000
Subject: note 34474 modified in function.call-user-func by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79929@lists.php.net to get a copy of this message
I had a problem where I wanted to parameterize a callback. The end called was in an external class, but I needed to save some state for the callback that didn't make sense to keep in the original object, as it might change from call to call... <?php class foo { function foo() { $str = "Hello There"; $str2 = "Carl"; $that =& new holder($str); call_user_func(array(&$that, 'callback'), $str2); } } class holder { function holder($aParam) { $this->param = $aParam; } function callback($aStr) { echo "A=$this->param, B=$aStr\n"; } } ?> --was-- I had a problem where I wanted to parameterize a callback. The end called was in an external class, but I needed to save some state for the callback that didn't make sense to keep in the original object, as it might change from call to call... class foo { function foo() { $str = "Hello There"; $str2 = "Carl"; $that =& new holder($str); call_user_func(array(&$that, 'callback'), $str2); } } class holder { function holder($aParam) { $this->param = $aParam; } function callback($aStr) { echo "A=$this->param, B=$aStr\n"; } } http://php.net/manual/en/function.call-user-func.php

« previous php.notes (#79929) next »