php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34650 pcntl with classes doesn't work as it should (works with PHP 5.1)
Submitted: 2005-09-26 21:23 UTC Modified: 2005-12-24 02:14 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: dcpiper at indiana dot edu Assigned:
Status: Wont fix Package: PCNTL related
PHP Version: 4.4.0 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dcpiper at indiana dot edu
New email:
PHP Version: OS:

 

 [2005-09-26 21:23 UTC] dcpiper at indiana dot edu
Description:
------------
I have noticed that even though a class function can be registered as a callback, it is not possible to set/update a class variable from within the signal handler and get it to be set within the actual 'live' instance of that object.

Is this a bug? It seems cumbersome to have to resort to global variables in order to actually DO something with the signal other than print out strings saying 'I got one!'

Reproduce code:
---------------
class SigTest {
  var $myvalue;
  
  function SignalHandler($signo) {
    echo "Got signal $signo \n";
    $this->myvalue = $signo;
    echo "in SignalHandler:\n";
    var_dump($this);
  }
  
  function SigTest() {
    declare (ticks = 1);
    $this->myvalue = 'some initial state';
    echo "Setting signal handlers ... ";
    pcntl_signal(SIGTERM, array(&$this, 'SignalHandler'));
    pcntl_signal(SIGINT, array(&$this, 'SignalHandler'));
    pcntl_signal(SIGHUP, array(&$this, 'SignalHandler'));
    $this->something = 'This data was set after the handler was instantiated';
    echo "Done\n";
  }
}
$jm = new SigTest;
sleep(2);
echo "Generating signal to self...\n";
posix_kill(posix_getpid(), SIGTERM);
echo "Main execution, looking at \$jm object:\n";
var_dump($jm);

Expected result:
----------------
Expected that 'myvalue' class variable change from within signal handler was visible outside of that function, i.e. a change made, not reverted to the state it was in previously before the signal was handled.


Actual result:
--------------
Setting signal handlers ... Done
Generating signal to self...
Got signal 15
in SignalHandler:
object(sigtest)(2) {
  ["myvalue"]=>
  int(15)
  ["something"]=>
  string(52) "This data was set after the handler was instantiated"
}
Main execution, looking at $jm object:
object(sigtest)(2) {
  ["myvalue"]=>
  string(18) "some initial state"
  ["something"]=>
  string(52) "This data was set after the handler was instantiated"
}

Last 'var_dump' SHOULD be the same as the first one, in my opinion.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-30 20:54 UTC] dcpiper at indiana dot edu
Yep, with the PHP5 snapshot it works fine. Do I have to upgrade everything to PHP5? The value is set correctly and maintained. I get this now:

/usr/src/apbuild/php5-200509301830/sapi/cli/php signaltest.php

Setting signal handlers ... Done
Generating signal to self...
Got signal 15
in SignalHandler:
object(SigTest)#1 (2) {
  ["myvalue"]=>
  int(15)
  ["something"]=>
  string(52) "This data was set after the handler was instantiated"
}
Main execution, looking at $jm object:
object(SigTest)#1 (2) {
  ["myvalue"]=>
  int(15)
  ["something"]=>
  string(52) "This data was set after the handler was instantiated"
}
 [2005-09-30 21:10 UTC] sniper@php.net
No, you don't _have_ to start using PHP 5. You can wait til eternity for someone to actually fix this in PHP 4. :)
(I just wanted to know that this only happens with PHP 4)

Yet another reason to update.

 [2005-12-24 02:14 UTC] sniper@php.net
Anything related to OO will never change with PHP 4. To get the best OO support -> upgrade to PHP 5.1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC