PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




register_tick_function

Name

register_tick_function — Registers a tick function.

Synopsis

bool register_tick_function(function/method[, . . .]);
array|string function/method: Function name to register or array containing object and method data
mixed . . . (optional): Argument to pass to the function or methodAdditional arguments

Returns

TRUE on success; FALSE otherwise

Description

register_tick_function() registers a function as a tick function. Tick functions are automatically called within declare control blocks. For a detailed overview of ticks, see the introduction at the beginning of this chapter.

The first argument for register_tick_function() can be either a string containing the name of a function, or a two-element array containing an object as the first element and the name of a method from the object as the second element.

The second and subsequent arguments are optional. If used, the arguments are passed to the function or method named in function/method . The arguments can be literal values, variables, or variables passed by reference.

Version

PHP Version: 4.0.3+

Example

Example 1320. Build a simple debugger using ticks

<pre>
<?php
/* Ticks make it easy to have a function called for every line of PHP
 *  code. We can use this to track the state of a variable throughout
 * the execution of a script.
 */

// If a global variable does not match the last
// value we saw for it, display the current value
function track_variables ($key) {
   static $last = '';

   $line = str_repeat ('-', 60);

   if ($last !== $GLOBALS[$key]) {
      echo "\n$line\n\$GLOBALS['$key'] --&gt; ";
      var_dump ($GLOBALS[$key]);
      echo "$line\n";
   }

   $last = $GLOBALS[$key];
}

// Register our tick function - have it track the foo variable
register_tick_function ('track_variables', 'foo');

// Watch the output
declare (ticks=1) {
    $foo = 10;
    echo "<br>Hi!";
    $foo *= $foo;
    $foo = 'bar';
       echo "<br>Gotta run";
    $foo = array (1,2,3);
    echo "<br>Bye!";
}
?>
</pre>



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.