note 46077 added to language.references.pass

From: Date: Tue, 28 Sep 2004 16:46:31 +0000
Subject: note 46077 added to language.references.pass
Groups: php.notes 
Request: Send a blank email to php-notes+get-77536@lists.php.net to get a copy of this message
Strangely enough, I had to put "&" on the call site, but not on the function parameter list, in order to get this to work. Here is the code: <?php class TestRunner { var $passed; var $failed; var $tests; function TestRunner() { $this->passed = 0; $this->failed = 0; $this->tests = array(); } function addTest($test) { $this->tests[] = $test; } function signalFailed() { $this->failed++; } function runTests() { foreach ($this->tests as $i => $eachName) { call_user_func($eachName, &$this); } } function report() { ?> <p><?= count($this->tests) ?> run, <?= $this->passed ?> passed, <?= $this->failed ?> failed</p> <?php } } function testNullStringIsEmpty($testRunner) { $testRunner->signalFailed(); } $testRunner = new TestRunner; $testRunner->addTest("testNullStringIsEmpty"); $testRunner->runTests(); $testRunner->report(); ?> Notice that testNullStringIsEmpty() does not declare that it wants a reference to a test runner, whereas on the function call site, we pass in &$this. When I run this, I get "1 run, 0 passed, 1 failed"; but when I switch the location of the & to the function parameter list, I get "1 run, 0 passed, 0 failed". This is the exact opposite to what the manual claims. I have no idea why that is. ---- Manual Page -- http://www.php.net/manual/en/language.references.pass.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46077 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46077&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46077&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77536) next »