note 37460 deleted from function.register-shutdown-function by crell
| From: | crell@php.net | Date: | Wed, 30 Mar 2022 22:04:59 +0000 |
| Subject: | note 37460 deleted from function.register-shutdown-function by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217806@lists.php.net to get a copy of this message | ||
Note Submitter: phpmanual at NO_SPHAMnetebb dot com
----
Given this code:
<?php
class CallbackClass {
function CallbackFunction() {
// refers to $this
}
function StaticFunction() {
// doesn't refer to $this
}
}
function NonClassFunction() {
}
?>
there appear to be 3 ways to set a callback function in PHP (using register_shutdown_function() as
an example):
1: register_shutdown_function('NonClassFunction');
2: register_shutdown_function(array('CallbackClass', 'StaticFunction'));
3: $o =& new CallbackClass();
register_shutdown_function(array($o, 'CallbackFunction'));
The following may also prove useful:
<?php
class CallbackClass {
function CallbackClass() {
register_shutdown_function(array(&$this, 'CallbackFunction')); // the & is
important
}
function CallbackFunction() {
// refers to $this
}
}
?>