ID:               34235
 Updated by:       [EMAIL PROTECTED]
 Reported By:      christian dot mueller at dfpx dot de
-Status:           Assigned
+Status:           Closed
 Bug Type:         PDO related
 Operating System: *
 PHP Version:      5CVS-2005-08-30
 Assigned To:      helly
 New Comment:

Works in php 5.1:
php -r 'class T extends PDO{function
exec(){var_dump("myexec");}function f(){}}$o=new
T("sqlite::memory:");$o->exec();ReflectionClass::export("T");'

PDO doesn't support 5.0 atm.


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

[2005-08-24 20:22:46] volka at cs dot tu-berlin dot de

method_exists() returning true but the actual call failing is
bewildering to say the least
--8<---8<---
<?php
class MTFrame_DB_PDOStatement extends PDOStatement
{
        public function execute()
        { return; }

        public function foo()
        { return; }
}

class MTFrame_DB_PDO extends PDO
{
        function prepare($sql)
        {
                return parent::prepare($sql,
array(PDO_ATTR_STATEMENT_CLASS=>array('MTFrame_DB_PDOStatement')));
        }
}

$m = new MTFrame_DB_PDO('sqlite:mydb.sq3');
$stmt = $m->prepare("SELECT COUNT(*) FROM sqlite_master WHERE
type='table'");

if ( method_exists($stmt, 'foo') )
        $stmt->foo();
else
        echo 'no such method';
?>
-->8--->8---

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

[2005-08-24 18:13:11] christian dot mueller at dfpx dot de

The manual (or further sources) does not state, that
PDOStatement::execute() can't be overridden or that PDO::prepare()
returns a somewhat castrated object.

var_dump($stmt) identifies $stmt as of MTFrame_DB_PDOStatement, just as
in my "reproduce code". But the object lacks method foo(). Better said,
the object acts, as if it was a plain PDOStatement. This is no
expected, please correct me.

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

[2005-08-24 15:59:14] christian dot mueller at dfpx dot de

Description:
------------
When i try to override PDO_Statement::execute(), my Method is ignored
completly.

When i try to implement ::foo() in my extending class, PHP states it is
undefined.

Reproduce code:
---------------
<?php

class MTFrame_DB_PDOStatement extends PDOStatement
{

    public function execute()
    {
        throw new Exception();
        // Nothing happens, i'm ignored
    }

    public function foo()
    {
        throw new Exception();
        // i do not exist?
    }
}

class MTFrame_DB_PDO extends PDO
{
    function prepare($sql)
    {
        return parent::prepare($sql,
array(PDO_ATTR_STATEMENT_CLASS=>array('MTFrame_DB_PDOStatement')));
    }
    
    function query($sql)
    {
        $stmt = parent::prepare($sql,
array(PDO_ATTR_STATEMENT_CLASS=>array('MTFrame_DB_PDOStatement')));
        $stmt->foo();
        return $stmt;
    }
}

?>

Actual result:
--------------
MTFrame_DB_PDOStatement::execute() gets ignored.

calling ::foo() produces:
Call to undefined method MTFrame_DB_PDOStatement::foo() 


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


-- 
Edit this bug report at http://bugs.php.net/?id=34235&edit=1

Reply via email to