phalcon/dd

[bug] can not dump object with \Phalcon\Debug\Dump second param set to true

itbdw opened this issue · 4 comments

itbdw commented

Can not dump object.

dump($this->request);die(1);
dump($e->getTrace());die(1);

Both throw an exception Exception: The argument is not initialized or iterable() in phalcon/debug/dump.zep on line 215

And the symfony/var-dumper show the code more cool...

Phalcon version : 3.4.0
PHP Version: 7.0.24

As a result, I use symfony/var-dumper to debug now.

https://packagist.org/packages/symfony/var-dumper#v3.4.11

Could you please explain a bit more. Is it issue, feature request, just news, something other?

itbdw commented
  1. It's a bug can not dump object with Dump class's second param set to true

@param boolean $detailed debug object's private and protected properties
https://github.com/phalcon/cphalcon/blob/master/phalcon/debug/dump.zep#L55

  1. The definition is public function __construct(array styles = [], boolean detailed = false), but just pass the first param with null in the helper. But it seems works fun.
        $foo = new \Exception('ss');

        //or 
        $foo = (object)['foo'=>'bar'];

        //works
        echo (new \Phalcon\Debug\Dump(null, false))->variable($foo);die;
        
        //doesn't work, throw the exception
        echo (new \Phalcon\Debug\Dump(null, true))->variable($foo);die;
        
        //Code in dd helper
        function dump()
        {
            array_map(function ($x) {
                $string = (new Dump(null, true))->variable($x);

                echo (PHP_SAPI == 'cli' ? strip_tags($string) . PHP_EOL : $string);

            }, func_get_args());
        }

I am facing exactly the same issue. Below call used to work for me earlier but doesn't work now a days. It shows exactly the same error as @itbdw wrote.

[Mon, 16 Jul 18 13:02:18 +0530][ERROR] Exception[0]: The argument is not initialized or iterable()
[Mon, 16 Jul 18 13:02:18 +0530][INFO] phalcon/debug/dump.zep[215]
[Mon, 16 Jul 18 13:02:18 +0530][DEBUG] Trace: 
#0 [internal function]: Phalcon\Debug\Dump->output(Object(Myapp\Models\CoFinyearM), 'var 0')
#1 [internal function]: Phalcon\Debug\Dump->variable(Object(Myapp\Models\CoFinyearM), 'var 0')
...

when I use below code

echo (new \Phalcon\Debug\Dump([], true))->variables($co_finyear) ;

Phalcon 3.3.2 64bit on Windows 7 with Wamp
PHP 7.0.10

As I can see there is no problem with latest stable Phalcon:

Test with dd:

require 'src/helper.php';

$foo = (object)['foo'=>'bar']
dd($foo);

Output:

Object stdClass (
  ->foo (public) = String (3) "bar"
  stdClass methods: (0) (
  )
)

Test with Phalcon\Debug\Dump:

require 'src/helper.php';

$foo = (object)['foo'=>'bar']
echo (new \Phalcon\Debug\Dump(null, true))->variable($foo);die;

Output:

<pre style='background-color:#f3f3f3; font-size:11px; padding:10px; border:1px solid #ccc; text-align:left; color:#333'><b style='color:purple'>Object</b> stdClass (
  -><span style='color:purple'>foo</span> (<span style='color:purple'>public</span>) = <b style='color:teal'>String</b> (<span style='color:teal'>3</span>) "<span style='color:teal'>bar</span>"
  stdClass <b style='color:purple'>methods</b>: (<span style='color:purple'>0</span>) (
  )
)</pre>