php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67102 strange throw
Submitted: 2014-04-21 11:28 UTC Modified: 2014-04-21 20:22 UTC
From: hewei986532 at sina dot com Assigned: - (profile)
Status: Not a bug Package: pthreads (PECL)
PHP Version: 5.4.27 OS: centos 5.4
Private report: No CVE-ID: None
 [2014-04-21 11:28 UTC] hewei986532 at sina dot com
Description:
------------
throw an error ‘
Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in /mnt/hgfs/www/test2.php:5 Stack trace: #0 /mnt/hgfs/www/test2.php(5): test::map() #1 /mnt/hgfs/www/test2.php(12): test->map(Array) #2 {main} thrown in /mnt/hgfs/www/test2.php on line 5’ when the class extends class

Test script:
---------------
class test extends Worker {
    public function map($t)
    {
        $this->a = $t;var_dump($this->a);exit;
    }
}
$map = new test;
$function = function($i){
    return $i;
};
$c = 1000000;$map->map(array($function, array($c)));

Expected result:
----------------
array(2) { [0]=> object(Closure)#2 (1) { ["parameter"]=> array(1) { ["$i"]=> string(10) "" } } [1]=> array(1) { [0]=> int(1000000) } } 

Actual result:
--------------
Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in /mnt/hgfs/www/lib/MapReduce.php:15 Stack trace: #0 /mnt/hgfs/www/lib/MapReduce.php(15): MapReduce::map() #1 /mnt/hgfs/www/lib/MapReduce.php(39): MapReduce->map(Array) #2 {main} thrown in /mnt/hgfs/www/lib/MapReduce.php on line 15

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-21 20:21 UTC] bwoebi@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: bwoebi
 [2014-04-21 20:21 UTC] bwoebi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

pthreads internally serializes the variables when passing them across threads.

That means you only can pass serializable variables to another threads. To pass functions across threads, you need other types of callables.
 [2014-04-21 20:22 UTC] bwoebi@php.net
-Status: Closed +Status: Not a bug -Assigned To: bwoebi +Assigned To: -
 [2014-04-22 02:08 UTC] hewei986532 at sina dot com
Bwoebi ,I do not know your name, so the first call you.Thank you very much answered my doubts, I'm sorry did not look carefully, so missed the phrase 
'That means you only can pass serializable variables to another threads. To pass functions across threads, you need other types of callables',I think it's very important for developers , it's the better if you can send in a very visible location! At last, I want to say pthreads is a good extension , thank you, and we look forward to many years.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 15:01:27 2019 UTC