|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-03-16 01:29 UTC] brian at moonspot dot net
Description:
------------
If you use a class method as the function for doing work and you return a private variable of the class as the result, the private variable is set to null.
Reproduce code:
---------------
<?php
class Foo {
private $count = 0;
public function run($job) {
$this->count++;
return $this->count;
}
}
$foo = new Foo();
$w = new GearmanWorker();
$w->addServer("127.0.0.1");
$w->addFunction("foo", array($foo, "run"));
while($w->work());
?>
Expected result:
----------------
On each run of this function, the result should increase by 1.
Actual result:
--------------
The result of this function is always 1.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 03:00:01 2025 UTC |
Yeah, even $w = new GearmanWorker(); $w->addServer("127.0.0.1"); $count = '3'; $w->addFunction("foo", function($job) use ($count) { return $count; }); while($w->work()); -- $c = new GearmanClient(); $c->addServer("127.0.0.1"); var_dump($c->do('foo', '')); var_dump($c->do('foo', '')); Outputs string(1) "3" string(0) "" Seems the return zval is getting freed/destroyed when it should be.