RussellReal Posted January 26, 2009 Share Posted January 26, 2009 like.. for example: <?php class TestCallback { private $variable; private function handleWalk($theValue) { echo "<h1><b>{$this->variable}</b></h1><br />"; echo $theValue.'<br />'; } public function goTest() { $this->variable = 'TEST!!!'; $abc = array('lol','omg'); array_walk($abc,'$this->handleWalk'); } } $t = new TestCallBack(); $t->goTest(); ?> NOW I know that won't work since, when the callback is triggered.. it will not know what $this is, but if I did like TestCallBack::handleWalk instead of $this->handleWalk it will most likely work.. I want callback functions to be able to be a method within the $this object inside my class.. if I'm making any sence.. in other words.. I want to keep it all within the class, instead of another class to extend the main class in order to do this Quote Link to comment https://forums.phpfreaks.com/topic/142453-solved-can-i-use-a-class-method-as-a-callback-function-for-functions-like-array_walk/ Share on other sites More sharing options...
Mchl Posted January 26, 2009 Share Posted January 26, 2009 Try array_walk($abc,array($this,"handleWalk")); see examples here http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback Quote Link to comment https://forums.phpfreaks.com/topic/142453-solved-can-i-use-a-class-method-as-a-callback-function-for-functions-like-array_walk/#findComment-746384 Share on other sites More sharing options...
RussellReal Posted January 26, 2009 Author Share Posted January 26, 2009 ok.. thank you so much, that made my life alot easier I have been helping here for like 2 months or so or a month I'm not exactly sure.. and so like I was on now and was like.. "Hey why not ask and see if its possible", so I asked.. lol and I've been puzzled over this since like a year ago already.. so, thank you very much for your reply Quote Link to comment https://forums.phpfreaks.com/topic/142453-solved-can-i-use-a-class-method-as-a-callback-function-for-functions-like-array_walk/#findComment-746386 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.