note 113686 added to gearmanclient.addtask
| From: | JeremyZerr | Date: | Fri, 15 Nov 2013 18:14:02 +0000 |
| Subject: | note 113686 added to gearmanclient.addtask | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197536@lists.php.net to get a copy of this message | ||
As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is
deprecated when you use & in $client->addTask(..., ..., &$results, ...);. And as of PHP
5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.
So that means that when you call addTask with a context parameter as in the example above like this:
<?php
# Add some tasks for a placeholder of where to put the results
$results = array();
$client->addTask("reverse", "Hello World!", &$results, "t1");
?>
You get this "call-time pass-by-reference" warning (or error). This can be avoided and
still result in functional code by changing the context variable to be an object so that it is
passed by reference like this:
<?php
$results = new \stdClass();
$client->addTask("reverse", "Hello World!", $results, "t1");
?>
Then for completeness, change the complete handler to expect a reference:
<?php
function reverse_complete($task, &$results) { ... }
?>
Then inside the complete handler, you can use the $results object to save your results to be
accessible outside the complete handler.
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/gearmanclient.addtask.php
Edit -- https://master.php.net/note/edit/113686
Del: integrated -- https://master.php.net/note/delete/113686/integrated
Del: useless -- https://master.php.net/note/delete/113686/useless
Del: bad code -- https://master.php.net/note/delete/113686/bad+code
Del: spam -- https://master.php.net/note/delete/113686/spam
Del: non-english -- https://master.php.net/note/delete/113686/non-english
Del: in docs -- https://master.php.net/note/delete/113686/in+docs
Del: other reasons-- https://master.php.net/note/delete/113686
Reject -- https://master.php.net/note/reject/113686
Search -- https://master.php.net/manage/user-notes.php