Jump to content

[SOLVED] Can I use a class' method as a callback function for functions like array_walk


RussellReal

Recommended Posts

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

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 :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.