|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59122 Return values that are class private variables are null'd
Submitted: 2010-03-16 01:29 UTC Modified: 2011-05-17 09:09 UTC
From: brian at moonspot dot net Assigned: hradtke (profile)
Status: Closed Package: gearman (PECL)
PHP Version: 5.2.12 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
41 - 6 = ?
Subscribe to this entry?

 [2010-03-16 01:29 UTC] brian at moonspot dot net
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:

class Foo {
    private $count = 0;
    public function run($job) {
        return $this->count;

$foo = new Foo();

$w = new GearmanWorker();


$w->addFunction("foo", array($foo, "run"));



Expected result:
On each run of this function, the result should increase by 1.

Actual result:
The result of this function is always 1.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-17 14:56 UTC] Jared dot Williams at ntworld dot com
Adding an explict cast to string on the return fixes it..

return (string)$this->count;
 [2010-04-18 11:49 UTC] brian at moonspot dot net
Yes, that forces a copy. That is the workaround. But, clearly, this is not the right solution.
 [2010-04-18 13:46 UTC] Jared dot Williams at ntlworld dot com
Yeah, even

$w = new GearmanWorker();
$count = '3';
$w->addFunction("foo", function($job) use ($count) { return 
$count; });


$c = new GearmanClient();
var_dump($c->do('foo', ''));                             
var_dump($c->do('foo', ''));                            


string(1) "3"
string(0) ""

Seems the return zval is getting freed/destroyed when it 
should be.
 [2010-04-19 08:24 UTC] brian at moonspot dot net
In PHP 5.2 it does not destroy a global in a normal function or a static. I sat down with James Luedke last week and showed him exactly what was going on. It is going to trace it down to see why his code thinks it is ok to free for classes and I guess this use case as well.
 [2011-05-17 09:09 UTC]
This bug has been fixed in SVN.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on

In case this was a website problem, the change will show
up on the website in short time.
Thank you for the report, and for helping us make PECL better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 08:01:27 2024 UTC