8000 [Debug] a README for the debug extension · symfony/symfony@4bf9300 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bf9300

Browse files
[Debug] a README for the debug extension
1 parent eec5c92 commit 4bf9300

File tree

1 file changed

+71
-0
lines changed
  • src/Symfony/Component/Debug/Resources/ext

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Symfony Debug Extension
2+
=======================
3+
4+
This extension adds a ``symfony_zval_info($key, $array, $options = 0)`` function that:
5+
6+
- exposes zval_hash/refcounts, allowing e.g. efficient exploration of arbitrary structures in PHP,
7+
- does work with references, preventing memory copying.
8+
9+
Its behavior is about the same as:
10+
11+
.. code-block:: php
12+
13+
<?php
14+
15+
function symfony_zval_info($key, $array, $options = 0)
16+
{
17+
// $options is currently not used, but could be in future version.
18+
19+
if (!array_key_exists($key, $array)) {
20+
return null;
21+
}
22+
23+
$info = array(
24+
'type' => gettype($array[$key]),
25+
'zval_hash' => /* hashed memory address of $array[$key] */,
26+
'zval_refcount' => /* internal zval refcount of $array[$key] */,
27+
'zval_isref' => /* is_ref status of $array[$key] */,
28+
);
29+
30+
switch ($info['type']) {
31+
case 'object':
32+
$info += array(
33+
'object_class' => get_class($array[$key]),
34+
'object_refcount' => /* internal object refcount of $array[$key] */,
35+
'object_hash' => spl_object_hash($array[$key]),
36+
);
37+
break;
38+
39+
case 'resource':
40+
$info += array(
41+
'resource_id' => (int) substr((string) $array[$key], 13),
42+
'resource_type' => get_resource_type($array[$key]),
43+
'resource_refcount' => /* internal resource refcount of $array[$key] */,
44+
);
45+
break;
46+
47+
case 'array':
48+
$info += array(
49+
'array_count' => count($array[$key]),
50+
);
51+
break;
52+
53+
case 'string':
54+
$info += array(
55+
'strlen' => strlen($array[$key]),
56+
);
57+
break;
58+
}
59+
60+
return $info;
61+
}
62+
63+
To enable the extension from source, run:
64+
65+
.. code-block:: sh
66+
67+
phpize
68+
./configure
69+
make
70+
sudo make install
71+

0 commit comments

Comments
 (0)
0