FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=19136&edit=1

ID: 19136
Updated by: martin.beeger@indurad.com
Reported By: martin dot beeger at indurad dot com
-Summary: Infinite Resurcsion makes result object unuseable
+Summary: Infinite Recurcsion makes result object unuseable
Status: Open
Type: Bug
Package: MDB2
Operating System: Debian Squeeze
Package Version: 2.5.0b3
PHP Version: 5.3.7
Roadmap Versions:
New Comment:

-Summary: Infinite Resurcsion makes result object unuseable
+Summary: Infinite Recurcsion makes result object unuseable



Previous Comments:
------------------------------------------------------------------------

[2011-12-14 20:19:43] pizzard

Description:
------------
I spent 6 hours on this issue and also found a fix for it.
I an using MDB2 with pgsql and tried to just execute a simple query on
my database.
But for any query, i get a Buffered result object.
But acessing some method of it (like numRows() , gives me an
MDB2_Error.
Investigating the result object leads to the following Problem:
The object contains a reference to it at $this->result instead of the
ressource handle.
This leads to an infinite recursion and an error.
The reason for this is inside the Method mdb2->_wrapResult() of common
driver.
At line ~2570 there is
$result = new $class_name($this, $result, $limit, $offset);
Because in MDB2_Result_Common constuctor it says:
$this->result =& $result;
this assignment crashes all.
A new object is created, and saved in $result, but this contanis a
reference to result inside at $this->result now.
So $this->result is also modified from psql resource (which it should
be) to a pointer (reference) on the object itself.

Fix:
Add a $temp = $result; before this line and change it to:
$result = new $class_name($this, $temp, $limit, $offset);
Now because temp is copy of the ressource handler, it stays linked to
$this->result and all is fine.



Test script:
---------------
//you got a valid MDB2 handle in $mdb2
$res =& $mdb2->query("SELECT 1;");
echo (int)$res->numRows();


Expected result:
----------------
1

Actual result:
--------------
Warning: pg_num_rows() expects parameter 1 to be resource, object given
in my/path/MDB2/Driver/pgsql.php on line 1293
Notice: Object of class MDB2_Error could not be converted to int in
my/path/login.php on line xx


------------------------------------------------------------------------

Search Discussions

  • Danielc at Dec 19, 2011 at 11:57 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19136&edit=1

    ID: 19136
    Updated by: danielc@analysisandsolutions.com
    Reported By: martin dot beeger at indurad dot com
    Summary: Infinite Recurcsion makes result object unuseable
    -Status: Open
    +Status: Closed
    Type: Bug
    Package: MDB2
    Operating System: Debian Squeeze
    Package Version: 2.5.0b3
    PHP Version: 5.3.7
    -Assigned To:
    +Assigned To: danielc
    Roadmap Versions:
    New Comment:

    -Status: Open
    +Status: Closed
    -Assigned To:
    +Assigned To: danielc
    Looking at the code in svn.php.net, I see that
    MDB2_Result_Common::__construct() no longer assigns by reference.
    Please reopen the bug if the problem still appears in the next release.


    Previous Comments:
    ------------------------------------------------------------------------

    [2011-12-15 13:46:04] pizzard

    -Summary: Infinite Resurcsion makes result object unuseable
    +Summary: Infinite Recurcsion makes result object unuseable


    ------------------------------------------------------------------------

    [2011-12-14 20:19:43] pizzard

    Description:
    ------------
    I spent 6 hours on this issue and also found a fix for it.
    I an using MDB2 with pgsql and tried to just execute a simple query on
    my database.
    But for any query, i get a Buffered result object.
    But acessing some method of it (like numRows() , gives me an
    MDB2_Error.
    Investigating the result object leads to the following Problem:
    The object contains a reference to it at $this->result instead of the
    ressource handle.
    This leads to an infinite recursion and an error.
    The reason for this is inside the Method mdb2->_wrapResult() of common
    driver.
    At line ~2570 there is
    $result = new $class_name($this, $result, $limit, $offset);
    Because in MDB2_Result_Common constuctor it says:
    $this->result =& $result;
    this assignment crashes all.
    A new object is created, and saved in $result, but this contanis a
    reference to result inside at $this->result now.
    So $this->result is also modified from psql resource (which it should
    be) to a pointer (reference) on the object itself.

    Fix:
    Add a $temp = $result; before this line and change it to:
    $result = new $class_name($this, $temp, $limit, $offset);
    Now because temp is copy of the ressource handler, it stays linked to
    $this->result and all is fine.



    Test script:
    ---------------
    //you got a valid MDB2 handle in $mdb2
    $res =& $mdb2->query("SELECT 1;");
    echo (int)$res->numRows();


    Expected result:
    ----------------
    1

    Actual result:
    --------------
    Warning: pg_num_rows() expects parameter 1 to be resource, object given
    in my/path/MDB2/Driver/pgsql.php on line 1293
    Notice: Object of class MDB2_Error could not be converted to int in
    my/path/login.php on line xx


    ------------------------------------------------------------------------
  • Martin Beeger at Dec 20, 2011 at 12:16 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19136&edit=1

    ID: 19136
    Updated by: martin.beeger@indurad.com
    Reported By: martin dot beeger at indurad dot com
    Summary: Infinite Recurcsion makes result object unuseable
    -Status: Closed
    +Status: Critical
    Type: Bug
    Package: MDB2
    Operating System: Debian Squeeze
    -Package Version: 2.5.0b3
    +Package Version: 2.4.1
    PHP Version: 5.3.7
    Assigned To: danielc
    Roadmap Versions:
    New Comment:

    -Status: Closed
    +Status: Critical
    -Package Version: 2.5.0b3
    +Package Version: 2.4.1
    Yeah, i checked that, and it is truly fixed in svn, but the actual
    stable release still contains this bug which e.g. makes it completely
    unuseable with the postgresql driver (and all other drivers which doesd
    not implment a seperate result constructor, which some do).
    Should be also hotfixed in this release or it should be marked as
    completely unuseable somewere.


    Previous Comments:
    ------------------------------------------------------------------------

    [2011-12-20 00:57:18] danielc

    -Status: Open
    +Status: Closed
    -Assigned To:
    +Assigned To: danielc
    Looking at the code in svn.php.net, I see that
    MDB2_Result_Common::__construct() no longer assigns by reference.
    Please reopen the bug if the problem still appears in the next release.

    ------------------------------------------------------------------------

    [2011-12-15 13:46:04] pizzard

    -Summary: Infinite Resurcsion makes result object unuseable
    +Summary: Infinite Recurcsion makes result object unuseable


    ------------------------------------------------------------------------

    [2011-12-14 20:19:43] pizzard

    Description:
    ------------
    I spent 6 hours on this issue and also found a fix for it.
    I an using MDB2 with pgsql and tried to just execute a simple query on
    my database.
    But for any query, i get a Buffered result object.
    But acessing some method of it (like numRows() , gives me an
    MDB2_Error.
    Investigating the result object leads to the following Problem:
    The object contains a reference to it at $this->result instead of the
    ressource handle.
    This leads to an infinite recursion and an error.
    The reason for this is inside the Method mdb2->_wrapResult() of common
    driver.
    At line ~2570 there is
    $result = new $class_name($this, $result, $limit, $offset);
    Because in MDB2_Result_Common constuctor it says:
    $this->result =& $result;
    this assignment crashes all.
    A new object is created, and saved in $result, but this contanis a
    reference to result inside at $this->result now.
    So $this->result is also modified from psql resource (which it should
    be) to a pointer (reference) on the object itself.

    Fix:
    Add a $temp = $result; before this line and change it to:
    $result = new $class_name($this, $temp, $limit, $offset);
    Now because temp is copy of the ressource handler, it stays linked to
    $this->result and all is fine.



    Test script:
    ---------------
    //you got a valid MDB2 handle in $mdb2
    $res =& $mdb2->query("SELECT 1;");
    echo (int)$res->numRows();


    Expected result:
    ----------------
    1

    Actual result:
    --------------
    Warning: pg_num_rows() expects parameter 1 to be resource, object given
    in my/path/MDB2/Driver/pgsql.php on line 1293
    Notice: Object of class MDB2_Error could not be converted to int in
    my/path/login.php on line xx


    ------------------------------------------------------------------------
  • Danielc at Dec 20, 2011 at 1:29 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=19136&edit=1

    ID: 19136
    Updated by: danielc@analysisandsolutions.com
    Reported By: martin dot beeger at indurad dot com
    Summary: Infinite Recurcsion makes result object unuseable
    -Status: Critical
    +Status: Closed
    Type: Bug
    Package: MDB2
    Operating System: Debian Squeeze
    Package Version: 2.4.1
    PHP Version: 5.3.7
    Assigned To: danielc
    Roadmap Versions:
    New Comment:

    -Status: Critical
    +Status: Closed
    We don't do hotfixes for earlier releases. It's fixed in the next active
    release.


    Previous Comments:
    ------------------------------------------------------------------------

    [2011-12-20 13:16:17] pizzard

    -Status: Closed
    +Status: Critical
    -Package Version: 2.5.0b3
    +Package Version: 2.4.1
    Yeah, i checked that, and it is truly fixed in svn, but the actual
    stable release still contains this bug which e.g. makes it completely
    unuseable with the postgresql driver (and all other drivers which doesd
    not implment a seperate result constructor, which some do).
    Should be also hotfixed in this release or it should be marked as
    completely unuseable somewere.

    ------------------------------------------------------------------------

    [2011-12-20 00:57:18] danielc

    -Status: Open
    +Status: Closed
    -Assigned To:
    +Assigned To: danielc
    Looking at the code in svn.php.net, I see that
    MDB2_Result_Common::__construct() no longer assigns by reference.
    Please reopen the bug if the problem still appears in the next release.

    ------------------------------------------------------------------------

    [2011-12-15 13:46:04] pizzard

    -Summary: Infinite Resurcsion makes result object unuseable
    +Summary: Infinite Recurcsion makes result object unuseable


    ------------------------------------------------------------------------

    [2011-12-14 20:19:43] pizzard

    Description:
    ------------
    I spent 6 hours on this issue and also found a fix for it.
    I an using MDB2 with pgsql and tried to just execute a simple query on
    my database.
    But for any query, i get a Buffered result object.
    But acessing some method of it (like numRows() , gives me an
    MDB2_Error.
    Investigating the result object leads to the following Problem:
    The object contains a reference to it at $this->result instead of the
    ressource handle.
    This leads to an infinite recursion and an error.
    The reason for this is inside the Method mdb2->_wrapResult() of common
    driver.
    At line ~2570 there is
    $result = new $class_name($this, $result, $limit, $offset);
    Because in MDB2_Result_Common constuctor it says:
    $this->result =& $result;
    this assignment crashes all.
    A new object is created, and saved in $result, but this contanis a
    reference to result inside at $this->result now.
    So $this->result is also modified from psql resource (which it should
    be) to a pointer (reference) on the object itself.

    Fix:
    Add a $temp = $result; before this line and change it to:
    $result = new $class_name($this, $temp, $limit, $offset);
    Now because temp is copy of the ressource handler, it stays linked to
    $this->result and all is fine.



    Test script:
    ---------------
    //you got a valid MDB2 handle in $mdb2
    $res =& $mdb2->query("SELECT 1;");
    echo (int)$res->numRows();


    Expected result:
    ----------------
    1

    Actual result:
    --------------
    Warning: pg_num_rows() expects parameter 1 to be resource, object given
    in my/path/MDB2/Driver/pgsql.php on line 1293
    Notice: Object of class MDB2_Error could not be converted to int in
    my/path/login.php on line xx


    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedDec 15, '11 at 12:46p
activeDec 20, '11 at 1:29p
posts4
users2
websitepear.php.net

2 users in discussion

Martin Beeger: 2 posts Danielc: 2 posts

People

Translate

site design / logo © 2022 Grokbase