From:             dcpiper at indiana dot edu
Operating system: Linux 2.6.13.1 (Debian Sarge)
PHP version:      4.4.0
PHP Bug Type:     Unknown/Other Function
Bug description:  pcntl with classes doesn't work as it should

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.

-- 
Edit bug report at http://bugs.php.net/?id=34650&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34650&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34650&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34650&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34650&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34650&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34650&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34650&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34650&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34650&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34650&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34650&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34650&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34650&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34650&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34650&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34650&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34650&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34650&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34650&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34650&r=mysqlcfg

Reply via email to