This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Debug/Resources/ext
2014-09-26 13:31:30 +02:00
..
tests [VarDumper] edge case fixes 2014-09-26 13:31:30 +02:00
config.m4 [VarDumper] edge case fixes 2014-09-26 13:31:30 +02:00
config.w32 [VarDumper] edge case fixes 2014-09-26 13:31:30 +02:00
php_symfony_debug.h [VarDumper] edge case fixes 2014-09-26 13:31:30 +02:00
README.rst [Debug] a README for the debug extension 2014-09-23 14:30:51 +02:00
symfony_debug.c [VarDumper] edge case fixes 2014-09-26 13:31:30 +02:00

Symfony Debug Extension
=======================

This extension adds a ``symfony_zval_info($key, $array, $options = 0)`` function that:

- exposes zval_hash/refcounts, allowing e.g. efficient exploration of arbitrary structures in PHP,
- does work with references, preventing memory copying.

Its behavior is about the same as:

.. code-block:: php

    <?php

    function symfony_zval_info($key, $array, $options = 0)
    {
        // $options is currently not used, but could be in future version.

        if (!array_key_exists($key, $array)) {
            return null;
        }

        $info = array(
            'type' => gettype($array[$key]),
            'zval_hash' => /* hashed memory address of $array[$key] */,
            'zval_refcount' => /* internal zval refcount of $array[$key] */,
            'zval_isref' => /* is_ref status of $array[$key] */,
        );

        switch ($info['type']) {
            case 'object':
                $info += array(
                    'object_class' => get_class($array[$key]),
                    'object_refcount' => /* internal object refcount of $array[$key] */,
                    'object_hash' => spl_object_hash($array[$key]),
                );
                break;

            case 'resource':
                $info += array(
                    'resource_id' => (int) substr((string) $array[$key], 13),
                    'resource_type' => get_resource_type($array[$key]),
                    'resource_refcount' => /* internal resource refcount of $array[$key] */,
                );
                break;

            case 'array':
                $info += array(
                    'array_count' => count($array[$key]),
                );
                break;

            case 'string':
                $info += array(
                    'strlen' => strlen($array[$key]),
                );
                break;
        }

        return $info;
    }

To enable the extension from source, run:

.. code-block:: sh

    phpize
    ./configure
    make
    sudo make install