fishingboy/madump

Magento Data Object Dump Tool

Maintainers

Package info

github.com/fishingboy/MaDump

pkg:composer/fishingboy/madump

Statistics

Installs: 55

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 3

1.1.3 2022-03-23 06:02 UTC

This package is auto-updated.

Last update: 2026-05-24 09:34:06 UTC


README

Tests Packagist Version Downloads License: MIT

English | 繁體中文

Why MaDump?

Calling var_dump() or print_r() on a Magento object causes an out-of-memory error because of deeply nested circular references. MaDump dumps only the first level of an object, giving you just enough information to navigate the code during development.

Installation

composer require fishingboy/madump

Usage

  1. Print directly

    use Fishingboy\MaDump\MaDump;
    MaDump::dump($product);

    Output:

    <pre>
    Magento\Catalog\Model\Product\Interceptor
        ->addAttributeUpdate($code, $value, $store)
        ->addCustomOption($code, $value, $product)
        ->addData(array $arr)
        ->addImageToMediaGallery($file, $mediaAttribute, $move, $exclude)
        ->addOption(Magento\Catalog\Model\Product\Option $option)
        ->afterCommitCallback()
        ->afterDelete()
        ->afterDeleteCommit()
        ->formatUrlKey($str)
        ->fromArray(array $data)
        ->getAttributeDefaultValue($attributeCode)
        ->getAttributeSetId() : 16 (string)
        ->getAttributeText($attributeCode)
        ->getAttributes($groupId, $skipSuper)
        ->getAvailableInCategories() : array
        ->getCacheIdTags() : array
        ->getCacheTags() : array
        ->getCalculatedFinalPrice() :  (NULL)
        ->getCategory() :  (NULL)
        ->getCategoryCollection() : Magento\Catalog\Model\ResourceModel\Category\Collection\Interceptor
        ...
    </pre>
  2. Capture as a string (for logging)

    use Fishingboy\MaDump\MaDump;
    $product_dump = MaDump::dump($product, true);
    $this->_logger->info("product => " . $product_dump);
  3. Stop execution after dumping

    use Fishingboy\MaDump\MaDump;
    MaDump::dump($product);
    exit;
  4. Typical trace workflow

    Step 1 — dump the top-level object:

    MaDump::dump($product);

    Step 2 — drill into an attribute:

    MaDump::dump($product->getCustomAttributes());

    Step 3 — drill further:

    MaDump::dump($product->getCustomAttributes()[0]);

    Keep going level by level until you find what you need.

Output Format

  1. Object

    <pre>
    Magento\Catalog\Model\Product\Interceptor
        ->addAttributeUpdate($code, $value, $store)
        ->addCustomOption($code, $value, $product)
        ->addData(array $arr)
        ->addImageToMediaGallery($file, $mediaAttribute, $move, $exclude)
        ->addOption(Magento\Catalog\Model\Product\Option $option)
        ->afterCommitCallback()
        ->afterDelete()
        ->afterDeleteCommit()
        ->formatUrlKey($str)
        ->fromArray(array $data)
        ->getAttributeDefaultValue($attributeCode)
        ->getAttributeSetId() : 16 (string)
        ->getAttributeText($attributeCode)
        ->getAttributes($groupId, $skipSuper)
        ->getAvailableInCategories() : array
        ->getCacheIdTags() : array
        ->getCacheTags() : array
        ->getCalculatedFinalPrice() :  (NULL)
        ->getCategory() :  (NULL)
        ->getCategoryCollection() : Magento\Catalog\Model\ResourceModel\Category\Collection\Interceptor
        ...
    </pre>

    Zero-argument getter methods are called automatically and their return values are shown inline:

        ->getAttributeSetId() : 16 (string)
        ->getCategoryCollection() : Magento\Catalog\Model\ResourceModel\Category\Collection\Interceptor
        ->getCacheIdTags() : array
  2. Array

    <pre>
    Array(52) =>
    [0] => (Magento\Framework\Api\AttributeValue)
    [10] => (Magento\Framework\Api\AttributeValue)
    [11] => (Magento\Framework\Api\AttributeValue)
    [12] => (Magento\Framework\Api\AttributeValue)
    ...
    </pre>

    Or for a simple array:

    <pre>
    Array(2) =>
    [0] => 101
    [1] => 102
    </pre>
  3. Scalar value

    <pre>1 (integer)</pre>
    <pre>true (boolean)</pre>
    <pre>sku-123 (string)</pre>

License

This project is licensed under the MIT License.