Add static local variables to the dump by JonathanGawrych · Pull Request #118 · BitOne/php-meminfo · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions extension/meminfo.c
1 change: 1 addition & 0 deletions extension/php_meminfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ zend_ulong meminfo_get_element_size(zval* z);
// Functions to browse memory parts to record item
void meminfo_browse_exec_frames(php_stream *stream, HashTable *visited_items, int *first_element);
void meminfo_browse_class_static_members(php_stream *stream, HashTable *visited_items, int *first_element);
void meminfo_browse_function_static_variables(php_stream *stream, char* class_name, HashTable *function_table, HashTable *visited_items, int *first_element);

void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * symbol_name, zval * zv, HashTable *visited_items, int *first_element);
void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, HashTable *visited_items, int *first_element);
Expand Down
46 changes: 46 additions & 0 deletions extension/tests/dump-class_function_static_local_variables.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
Check that static variables inside a class member function are accounted for
--SKIPIF--
<?php
if (!extension_loaded('json')) die('skip json ext not loaded');
?>
--FILE--
<?php
$dump = fopen('php://memory', 'rw');

class MyClass {
public function myMethod() {
static $staticLocalVar;

if (!isset($staticLocalVar)) {
$staticLocalVar = 'one time load';
}

return $staticLocalVar;
}
}

(new MyClass)->myMethod();

meminfo_dump($dump);

rewind($dump);
$meminfoData = json_decode(stream_get_contents($dump), true);
fclose($dump);

$myArrayDump = [];

foreach ($meminfoData['items'] as $item) {
if (isset($item['symbol_name']) && $item['symbol_name'] == '$staticLocalVar') {
echo "Symbol: " . $item['symbol_name'] . "\n";
echo " Frame: " . $item['frame'] . "\n";
echo " Type: " . $item['type'] . "\n";
echo " Is root: " . $item['is_root'] . "\n";
}
}
?>
--EXPECT--
Symbol: $staticLocalVar
Frame: <STATIC_VARIABLE(MyClass::myMethod)>
Type: string
Is root: 1
44 changes: 44 additions & 0 deletions extension/tests/dump-global_function_static_local_variables.phpt