note 37460 modified in function.register-shutdown-function by danbrown

From: Date: Sat, 19 Jul 2008 23:18:27 +0000
Subject: note 37460 modified in function.register-shutdown-function by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141788@lists.php.net to get a copy of this message
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 } } ?> --was-- Given this code: 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: class CallbackClass { function CallbackClass() { register_shutdown_function(array(&$this, 'CallbackFunction')); // the & is important } function CallbackFunction() { // refers to $this } } http://php.net/manual/en/function.register-shutdown-function.php

« previous php.notes (#141788) next »