通过类中的引用传递函数

I was trying to pass a function (from within the same class) by reference to another function for that function to execute, however it doesn't seem to work. I can do this outside a class but not from within a class: is there a way to do this properly?

class test {
  function test() {
    $this->check(1==2, &$this->t(), &$this->f()); 
  }

  function check($statement, $true, &$false) {
    if(eval($statement)) {
      $true;
    }
    $false;
  }

  function t() {
    print "true";
    return true;
  }

  function f() {
    print "false";
    return false;
  }
}

Passing by reference at call-time is deprecated (and indeed removed since 5.4):

As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);. And as of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.

From php's docs.
There's also no real point in passing a reference to a boolean. The memory a PHP reference will take up is, in theory, the same as a C pointer (4 bytes), a boolean will probably be a (short) int, which only requires 2 bytes. If anything, I'd say you're generating more overhead.

If you're passing an object or array by reference to another function/method, you'll have to define the funciton accordingly:

function doStuff_byRef(array &$arg)
{
    $arg[] = 'add new stuff';
}

Passing a function by reference, as you'd do in JS, isn't possible in PHP. However, you can define a function not to return a value, but return a reference to its return value:

public function &getPropertyRef()
{
    return $this->property;
}

In your case, however, I'd simply do this:

$this->check(1==2, 't', 'f');//pass method names
private function check($stmt, $func1, $func2)
{
    //don't use eval, btw
    if ($stmt)
    {
        return $this->{$func1}();
    }
    return $this->{$func2}();
}

Or, even more flexible:

$this->check(1==2, array($this, 't'), array($this, 'f'));//pass method names
private function check($stmt, array $func1, array $func2)
{
    //don't use eval, btw
    if ($stmt)
    {
        return call_user_func_array($func1);
    }
    return call_user_func_array($func2);
}

I suppose, if you have PHP >= 5.3, you could use a closure instance:

private function check($stmt, Closure &$func1, Closure &$func2)
{
    return $stmt ? $func1() : $func2();
}

Then, you could do this:

$functionReference = function()
{
    echo 'true';
    return true;
};
$functionRef2 = function()
{
    echo 'false';
    return false;
};
$this->check(true, $functionReference, $functionRef2);

But that's adding even more overhead: PHP closures are just one of those things that were added to the language, that shouldn't be there. It's creating an instance of the Closure class, at compile time, and that object is then being passed by reference. Honestly, the best way to go in your case is my first suggestion, still, IMHO ($this->{$func1}();)