<?php if (!extension_loaded("sqlite")) { dl("sqlite.so"); if (!extension_loaded("sqlite")) { exit("Please enable SQLite support\n"); } } debug_zval_dump(sqlite_libversion()); debug_zval_dump(sqlite_libencoding()); $s = sqlite_open("weztest.sqlite", 0666, $err); debug_zval_dump($err); debug_zval_dump($s); $r = sqlite_query("create table foo (a INTEGER PRIMARY KEY, b INTEGER )", $s); debug_zval_dump(sqlite_last_error($s)); debug_zval_dump(sqlite_error_string(sqlite_last_error($s))); $r = sqlite_query("select *, php('md5', sql) as o from sqlite_master", $s); debug_zval_dump($r); debug_zval_dump(sqlite_num_rows($r)); debug_zval_dump(sqlite_num_fields($r)); for ($j = 0; $j < sqlite_num_fields($r); $j++) { echo "Field {$j} is " . sqlite_field_name($r, $j) . "\n"; } while ($row = sqlite_fetch_array($r, SQLITE_ASSOC)) { print_r($row); } sqlite_close($s);
function dump_globalvar(&$local_var) { global $global_var; echo "\n-- Value of local variable inside dump_globalvar() --\n"; debug_zval_dump($local_var); echo "\n-- Value of global variable inside dump_globalvar() --\n"; debug_zval_dump($global_var); }
function zval_dump($values) { $counter = 1; foreach ($values as $value) { echo "-- Iteration {$counter} --\n"; debug_zval_dump($value); $counter++; } }
function foo($ref, $alt) { unset($GLOBALS['a']); unset($GLOBALS['b']); $GLOBALS['a'] = 1; $GLOBALS['b'] = 2; $org_a = $GLOBALS['a']; $org_b = $GLOBALS['b']; if ($ref) { global $a, $b; } else { /* zval temp_var(NULL); // refcount = 1 * a = temp_var[x] // refcount = 2 */ $a = NULL; $b = NULL; } debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); echo "--\n"; if ($alt) { $a =& $GLOBALS['a']; $b =& $GLOBALS['b']; } else { extract($GLOBALS, EXTR_REFS); } debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); echo "--\n"; $a =& $GLOBALS['a']; $b =& $GLOBALS['b']; debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); echo "--\n"; $GLOBALS['b'] = 3; debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); echo "--\n"; $a = 4; debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); echo "--\n"; $c = $b; debug_zval_dump($b, $GLOBALS['b'], $c); echo "--\n"; $b = 'x'; debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b'], $c); echo "--\n"; debug_zval_dump($org_a, $org_b); echo "----"; if ($ref) { echo 'r'; } if ($alt) { echo 'a'; } echo "\n"; }
function on_accept($stream, $flags, $event) { global $CLIENTS; $mem = memory_get_usage(); echo "on_accept({$stream}, {$flags}): mem={$mem} \n"; if (false === ($con = stream_socket_accept($stream, 0, $name))) { echo "Accept failed\n"; } else { echo "Peer:{$name}\n"; $client = bufferevent_new($con, 'on_read', 'on_write', 'on_error'); debug_zval_dump($client); // TODO: If bufferevent falls out of scope: disable and free buffer. also close stream. $CLIENTS[$name] = array(&$client, &$con); bufferevent_enable($client, EV_READ); } }
public function get($uid) { // hprint(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); // debug_print_backtrace(); // go(); xdebug; $a = array('a' => 'a'); debug_zval_dump($a); die; import('Mc'); $mc = Mc::getInstance(); hprint($mc); $mc->increment('aa', 1); $res = $mc->get('aa'); echo $res; echo '<br>'; //print_r($user->get()); }
/** * Inits class */ private static function init() { if (null !== self::$offset) { return; } // calculate offset and mask self::$offset = 16 - PHP_INT_SIZE; self::$mask = -1; $tested = (object) array(); if (defined('HHVM_VERSION')) { // HHVM specific self::$offset += 16; } else { // determine the mask to apply to object hashes ob_start(); debug_zval_dump($tested); $debug = ob_get_clean(); self::$mask = (int) substr($debug, strpos($debug, "#") + 1); } $relevantInt = self::getObjectHashRelevantInt($tested); self::$mask ^= $relevantInt; }
/** * Simple test for circular references * Example: detect_circular_references(get_defined_vars()); * Currently tries to detect recursion within objects * @param mixed $vars * @param array $refs * @param array $objrefs */ function detect_circular_references($vars = array(), &$refs = array(), &$objrefs = array()) { foreach ($vars as $name => $var) { if (is_array($var)) { detect_circular_references($var, $refs, $objrefs); } else { if (is_object($var)) { ob_start(); debug_zval_dump($var); $dump = ob_get_clean(); if (strpos($dump, '*RECURSION*') !== false) { //echo '*RECURSION*'; throw new CircularReferenceException('Circular reference in $' . $name); } /* $ref = spl_object_hash($var); if (isset($objrefs[$ref])){ throw new CircularReferenceException(); } $objrefs[$ref] = true; $reflection = new ReflectionObject($var); $properties = $reflection->getProperties(); $pvars = array(); foreach ($properties as $property) { if (version_compare(PHP_VERSION, '5.3', '>=')) { $property->setAccessible(true); // PHP 5.3 $pvars[] = $property->getValue(); } else { if ($property->isPublic()) { $pvars[] = $property->getValue(); } } } detect_circular_references($pvars, $refs, $objrefs); */ } } } }
require_once 'table.inc'; $references = array(); if (!mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1") || !($res = mysqli_store_result($link))) { printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $idx = 0; while ($row = mysqli_fetch_assoc($res)) { /* will overwrite itself */ $references[$idx]['row_ref'] =& $row; $references[$idx]['row_copy'] = $row; $references[$idx]['id_ref'] =& $row['id']; $references[$idx++]['id_copy'] = $row['id']; } debug_zval_dump($references); mysqli_free_result($res); if (!mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") || !($res = mysqli_use_result($link))) { printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $rows = array(); for ($i = 0; $i < 2; $i++) { $rows[$i] = mysqli_fetch_assoc($res); $references[$idx]['row_ref'] =& $rows[$i]; $references[$idx]['row_copy'] = $rows[$i]; $references[$idx]['id_ref'] =& $rows[$i]['id']; $references[$idx]['id_copy'] = $rows[$i]['id']; /* enforce separation */ $references[$idx]['id_copy_mod'] = $rows[$i]['id'] + 0; } mysqli_free_result($res); debug_zval_dump($references); print "done!";
function __call($name, $args) { debug_zval_dump($args); call_user_func_array('foo', $args); }
<?php $a = array(); $b =& $a; $a[0] = $a; debug_zval_dump($a); $a = array(array()); $b =& $a; $a[0][0] = $a; debug_zval_dump($a);
<?php if (getenv('REDIR_TEST_DIR') === false) { putenv('REDIR_TEST_DIR=' . dirname(__FILE__) . '/../../pdo/tests/'); } require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; $db = PDOTest::factory(); try { $ser = serialize($db); debug_zval_dump($ser); $db = unserialize($ser); $db->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val VARCHAR(10))'); } catch (Exception $e) { echo "Safely caught " . $e->getMessage() . "\n"; } echo "PHP Didn't crash!\n";
$row = array('id' => -1, '_bin' => -1, 'bit_value' => -1, '_bit_value0' => -1, 'bit_null' => -1); if (!mysqli_stmt_bind_result($stmt_sel, $row['id'], $row['_bin'], $row['bit_value'], $row['_bit_value0'], $row['bit_null'])) { printf("[010 - %d] [%d] %s\n", $bits, mysqli_stmt_errno($stmt_sel), mysqli_stmt_error($stmt_sel)); break; } if (!($ret = mysqli_stmt_fetch($stmt_sel))) { printf("[011 - %d] mysqli_stmt_fetch() has failed for %d bits - ret = %s/%s, [%d] %s, [%d] %s\n", $bits, $bits, gettype($ret), $ret, mysqli_stmt_errno($stmt_sel), mysqli_stmt_error($stmt_sel), mysqli_errno($link_sel), mysqli_errno($link_sel)); break; } if ($value != $row['id'] || $bin != $row['_bin'] && $bin2 != $row['_bin']) { debug_zval_dump($row); printf("[012 - %d] Insert of %s in BIT(%d) column might have failed. id = %s, bin = %s (%s/%s)\n", $bits, $value, $bits, $row['id'], $row['_bin'], $bin, $bin2); break; } if ($value != $row['bit_value']) { debug_zval_dump($row); printf("[013 - %d] Expecting %s got %s\n", $bits, $value, $row['bit_value']); break; } if (null !== $row['bit_null']) { debug_zval_dump($row); printf("[014 - %d] Expecting null got %s/%s\n", $bits, gettype($row['bit_value']), $row['bit_value']); break; } } mysqli_stmt_close($stmt_ins); mysqli_stmt_close($stmt_sel); } mysqli_close($link_ins); mysqli_close($link_sel); print "done!";
function checkDuplicities(&$menu, $msg = '') { echo "<br />\n" . $msg . "<br />\n"; // joomla defines duplicity as client_id, parent_id, alias, language $arr = array(); foreach ($menu as $key => &$item) { $str = $item['client_id'] . '-' . $item['parent_id'] . '-' . $item['alias'] . '-' . $item['language']; if (isset($arr[$str])) { $count = 1; $item['alias'] = $item['alias'] . '-' . $count; $this->tryAlias($menu, $item, $count); $str = $item['client_id'] . '-' . $item['parent_id'] . '-' . $item['alias'] . '-' . $item['language']; } $arr[$str] = $key; } $test = array(); $lftrgt = array(); foreach ($menu as $m1) { // if (empty($m1['parent_id'])) continue; // skip for root if (!empty($m1['parent_id'])) { $left = $m1['lft']; $right = $menu[$m1['parent_id']]['rgt']; if ($right <= $left) { $msg = "<br />\n" . 'parent id ' . $m1['parent_id'] . "<br />\n"; $msg .= ' right for parent: ' . $right . "<br />\n"; $msg .= ' left for item: ' . $left . " right for item " . $m1['rgt'] . " <br />\n"; $msg .= ' for item id ' . $m1['id'] . "<br />\n"; $msg .= ' error consistency right smaller left'; echo 'item:'; var_dump($m1); echo 'parent:'; var_dump($menu[$m1['parent_id']]); die('error consistency right smaller left' . $msg); } } if (!isset($lftrgt[$m1['lft']])) { $lftrgt[$m1['lft']] = $m1['id']; //if ($m1['lft']===0) die('ok'); } else { echo 'id ' . $m1['id'] . ' shares the same left with ' . $lftrgt[$m1['lft']] . "<br />\n"; debug_zval_dump($menu); die('shares...'); } if (!isset($lftrgt[$m1['rgt']])) { $lftrgt[$m1['rgt']] = $m1['id']; } else { echo 'id ' . $m1['id'] . ' shares the same right with ' . $lftrgt[$m1['rgt']] . "<br />\n"; echo ' count ' . count($menu); //debug_zval_dump($menu); die('shares the same right with.'); } } //var_dump($menu[1]); // -1 because we start from 0 $c = count($menu) * 2 - 1; for ($i = 0; $i < $c; $i++) { if (!isset($lftrgt[$i])) { echo ' 2: missing value for left or right on position ' . $i . "<br />\n"; echo 'count: ' . count($menu); echo 'before: '; var_dump($menu[$lftrgt[$i - 1]]); echo 'next: '; if (!isset($menu[$lftrgt[$i + 1]])) { var_dump($menu[1]); } var_dump($menu[$lftrgt[$i + 1]]); var_dump($menu[$lftrgt[$i + 2]]); //var_dump($menu[685]); die('2: missing'); } } }
/** * @param object $value * @param bool $includeCurrent * * @return int */ function getReferenceCount($value, $includeCurrent = \true) { \ob_start(); \debug_zval_dump($value); $ret = \explode("\n", \ob_get_contents()); \ob_end_clean(); if (\count($ret) >= 1 and \preg_match('/^.* refcount\\(([0-9]+)\\)\\{$/', \trim($ret[0]), $m) > 0) { return (int) $m[1] - ($includeCurrent ? 3 : 4); //$value + zval call + extra call } return -1; }
function refcount(&$var) { ob_start(); debug_zval_dump(array(&$var)); $rtn = preg_replace("/^.+?refcount\\((\\d+)\\).+\$/ms", '$1', substr(ob_get_clean(), 24), 1) - 4; echo "<br>refcount:" . $rtn; return $rtn; }
<?php class test { public static $x; public function __toString() { self::$x = $this; return __FILE__; } } $a = new test(); require_once $a; debug_zval_dump(test::$x);
public function dump($value, bool $detailed = true) { $detailed ? debug_zval_dump($value) : var_dump($value); }
<?php /** * User: blake * Date: 12/19/12 * Time: 11:58 PM * Creates a windows service for asteriskLogger.php, would be fairly trivial to add remove service support also. * see win32_remove_service. * * Instructions: * 1) copy the php_win32service.dll to your /ext directory. * 2) update your php.ini file to include extension=php_win32service.dll * 3) Run the script. If it failed, you need to find the correct php_win32service.dll for your particular php version / compiled settings * 4) Once script runs successfully, you'll see it in the services control panel. * 5) The script wouldn't start for me (Blake Robertson)... but I'm committing it anyway as maybe someone can take it from here. * * READ #5 above. */ if ($argc <= 1) { print "USAGE: php create_win_service.php <path to asteriskLogger.php>\n"; print " <path to asteriskLogger.php> is generally <SugarRoot>/custom/modules/Asterisk/asteriskLogger.php\n"; exit; } if (!file_exists($argv[1])) { print "ERROR: asteriskLogger.php not found at: {$argv['1']} set the path properly.\n"; } else { $x = win32_create_service(array('service' => 'asteriskLogger.php', 'display' => 'Asterisk Integration for SugarCRM', 'description' => 'Maintains an AMI connection with your pbx and posts events to your sugarcrm server', 'params' => '"' . $argv[1] . '"')); debug_zval_dump($x); }
echo "Hello, {$name}" . PHP_EOL; echo $arg . PHP_EOL; }; // $func('test'); function getCounter() { $i = 0; return function () use($i) { // 这里如果使用引用传入变量: use(&$i) echo ++$i; }; } $counter = getCounter(); // $counter(); // 1 // $counter(); // 1 $i2 = 100; $counter = function () use($i2) { debug_zval_dump($i2); }; // $counter(); $a = 1; $b =& $a; // debug_zval_dump($a); // refcount(1) a new copy //php-5.3.0 $class = new ReflectionClass("Closure"); var_dump($class->isInternal()); var_dump($class->isAbstract()); var_dump($class->isFinal()); var_dump($class->isInterface()); // vim600:ts=4 st=4 foldmethod=marker foldmarker=<<<,>>> // vim600:syn=php commentstring=//%s
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) { printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket); } if (!mysqli_real_query($link, "SELECT id, label FROM test_mysqli_result_references_table_1 ORDER BY id ASC LIMIT 2") || !($res = mysqli_use_result($link))) { printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } while ($row = mysqli_fetch_assoc($res)) { /* mysqlnd: force seperation - create copies*/ $references[$idx] = array('id' => &$row['id'], 'label' => $row['label'] . ''); $references[$idx]['id2'] =& $references[$idx]['id']; $references[$idx]['id'] += 1; $references[$idx++]['id2'] += 1; } $references[$idx++] =& $res; mysqli_free_result($res); @debug_zval_dump($references); if (!mysqli_real_query($link, "SELECT id, label FROM test_mysqli_result_references_table_1 ORDER BY id ASC LIMIT 1") || !($res = mysqli_use_result($link))) { printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $tmp = array(); while ($row = mysqli_fetch_assoc($res)) { $tmp[] = $row; } $tmp = unserialize(serialize($tmp)); debug_zval_dump($tmp); mysqli_free_result($res); mysqli_close($link); print "done!"; error_reporting(0); $test_table_name = 'test_mysqli_result_references_table_1'; require_once "clean_table.inc";
public static function refcount($var, &$refs = null) { ob_start(); debug_zval_dump($var); $refs = ob_get_contents(); ob_end_clean(); $c = PHP_INT_MAX; $ret = preg_match("/ refcount\\((\\d+)\\)/ms", $refs, $mats); if ($ret) { $c = $mats[1] - 3; } return $c; }
<?php require_once './inc/func_main.php'; MySQL_Query("CREATE TABLE nw_unread (id int NOT NULL PRIMARY KEY AUTO_INCREMENT, idtable int, idrecord int, iduser int)"); $sql = "SELECT id as 'id' FROM " . DB_PREFIX . "users"; $res = MySQL_Query($sql); while ($rec_utc = MySQL_Fetch_Assoc($res)) { MySQL_Query("INSERT INTO nw_unread (idtable,idrecord) SELECT idtable,idrecord FROM nw_unread_" . $rec_utc['id']); MySQL_Query("UPDATE nw_unread SET iduser = "******" WHERE iduser IS NULL;"); MySQL_Query("DROP TABLE nw_unread" . $rec_utc['id']); echo 'vysledek=' . $rec_utc; print_r($rec_utc); debug_zval_dump($rec_utc); echo '<br />'; }
<?php $debugArray = array(1, 2, 3); foreach ($debugArray as $v) { $v *= 2; debug_zval_dump($v); } var_dump($debugArray); $debugArray2 = array(1, 2, 3); foreach ($debugArray2 as &$v) { $v *= 2; debug_zval_dump($v); } var_dump($debugArray2);
<?php class test { public static $x; public function __toString() { self::$x = $this; return __FILE__; } } $a = new test(); require_once $a; debug_zval_dump($a, test::$x);
<?php eval('function fun($x) { $x = \'x\'; }'); $h = $g; fun(&$h); debug_zval_dump($h);
/** * Count the number of references to the value pointed by given variable. * The counting algorithm is based on Alexandre Quercia's work. * @link https://github.com/alquerci/php-types-autoboxing/blob/v1.0.0-BETA2/Memory/GarbageCollector.php Alexandre Quercia's Garbage Collector and refCount method * @param &mixed $var Variable to count references for * @return int */ private static function refCount(&$var) { ob_start(); debug_zval_dump(array(&$var)); return preg_replace('#^.+refcount\\((\\d+)\\)\\s*$#ms', '$1', ob_get_clean()) - 4; }
private static function initHashMask() { $obj = (object) array(); self::$hashOffset = 16 - PHP_INT_SIZE; self::$hashMask = -1; if (defined('HHVM_VERSION')) { self::$hashOffset += 16; } else { // check if we are nested in an output buffering handler to prevent a fatal error with ob_start() below $obFuncs = array('ob_clean', 'ob_end_clean', 'ob_flush', 'ob_end_flush', 'ob_get_contents', 'ob_get_flush'); foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) { if (isset($frame['function'][0]) && !isset($frame['class']) && 'o' === $frame['function'][0] && in_array($frame['function'], $obFuncs)) { $frame['line'] = 0; break; } } if (!empty($frame['line'])) { ob_start(); debug_zval_dump($obj); self::$hashMask = substr(ob_get_clean(), 17); } } self::$hashMask ^= hexdec(substr(spl_object_hash($obj), self::$hashOffset, PHP_INT_SIZE)); }
<?php // Reduced from test/subjects/codegen/functioncalls_evald_functions.php with phc arguments "--run=plugins/tools/debug_zval.la --dump=plugins/tools/debug_zval.la" function fun_r(&$x) { $x = 'x'; } fun_r($r); debug_zval_dump($r);
<?php $test = array("AB" => "Hello world"); var_dump($test); var_export($test); debug_zval_dump($test);