php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67506 closures as callbacks
Submitted: 2014-06-24 14:46 UTC Modified: 2014-09-18 20:07 UTC
From: very-hot at gmx dot at Assigned: krakjoe (profile)
Status: Closed Package: pthreads (PECL)
PHP Version: 5.5.13 OS: Win 8.1
Private report: No CVE-ID: None
 [2014-06-24 14:46 UTC] very-hot at gmx dot at
Description:
------------
PHP-Version 5.5.11

http://www.php.net/manual/en/class.thread.php

class Thread should accept closures.

Test script:
---------------
<?php
   error_reporting(~0);

   class T extends Thread
   {
      private $cCallback;
      private $i;

      /**
       * @param Closure $cCallback
       * @param int $i unique Thread number
       */
      function __construct(Closure $cCallback, $i)
      {
         $this->cCallback = $cCallback;
         $this->i = $i;
         var_dump($this->cCallback);
      }

      function run()
      {
         call_user_func_array($this->cCallback, [1]);
      }
   }
   
   // Callback function:
   $cCallback = function($i) 
   { 
      echo $i." finished\n"; 
   };
   
   $oT = new T($cCallback, 1);
   $oT->start(); 
?>

Expected result:
----------------
var_dump($this->cCallback); // Closure

Actual result:
--------------
var_dump($this->cCallback); // NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-18 18:40 UTC] jrthomas at mtu dot edu
This is happening on PHP v5.6, with pthreads v2.0.8 on Ubuntu 12.04.4 as well.
 [2014-09-18 20:07 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2014-09-18 20:07 UTC] krakjoe@php.net
This is fixed in soon to be released 2.0.9
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 18:01:31 2024 UTC