kint-php / kint

Kint - Advanced PHP dumper
https://kint-php.github.io/kint/
MIT License
2.77k stars 291 forks source link

Problem with PDOStatement and consuming objects #217

Closed salvoselene closed 7 years ago

salvoselene commented 7 years ago

Hi, this is more of a feature request than a issue. Could i prevent kint from iterating PDOStatement? The problem is that it consumes the resultset iterating over it and the data is not available past the dump, took me a lot to realize that the only problem in my page was the dump to verify the connection.

Here's my code for reference:

    $query = "select * from lollo";
    $db = Database::getInstance(); //returns PDO
    $result = $db->query($query);
    d($result); //dump
    $result->setFetchMode(PDO::FETCH_CLASS,'stdClass');
    while($row = $result->fetch()){ //does not even enter this
        d($row);
    }
jnvsor commented 7 years ago

Your only option here (Until 2.x is done) is to alter Kint source code - specifically you can delete parsers/custom/objectiterable.php to disable iterator debugging, or alter it to filter out PDOStatements.

diff --git a/parsers/custom/objectiterateable.php b/parsers/custom/objectiterateable.php
index bbc0de0..50010c2 100644
--- a/parsers/custom/objectiterateable.php
+++ b/parsers/custom/objectiterateable.php
@@ -8,6 +8,7 @@ class Kint_Parsers_objectIterateable extends kintParser
            || !is_object( $variable )
            || !$variable instanceof Traversable
            || stripos( get_class( $variable ), 'zend' ) !== false // zf2 PDO wrapper does not play nice
+           || $variable instanceof PDOStatement
        ) return false;
jnvsor commented 7 years ago

Fixed in 2.x-dev. Please test and give feedback, thanks!

salvoselene commented 7 years ago

Working like a charm, thanks!