php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44425 Extending PDO/MySQL class with a __call() function doesn't work
Submitted: 2008-03-13 04:52 UTC Modified: 2008-09-16 23:37 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phpbugs at wayoverthere dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.2CVS-2008-03-13 (snap) OS: Linux/Windows
Private report: No CVE-ID:
 [2008-03-13 04:52 UTC] phpbugs at wayoverthere dot com
Description:
------------
Exact(?) same bug as #43663, except connecting to a MySQL 5 server. I 
have also tried a 5.3 snapshot & got the same result. Tried both cgi 
and cli.


Reproduce code:
---------------
<?php
class test extends PDO {
    function __call($name, array $args) {
        echo "Called $name in ".__CLASS__.'<br>';
    }
    function foo() {
        echo "Called foo in ".__CLASS__.'<br>';
    }
}
$a = new test('mysql:dbname=test;host=localhost','user','pw');
$a->foo();
$a->bar();
?>


Expected result:
----------------
"Called foo in test
Called bar in test"

Actual result:
--------------
"Called foo in test

 Fatal error: Call to undefined method test::bar() in call.php on 
line 24"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-13 16:10 UTC] iliaa@php.net
Works fine in snapshot and PHP 5.3
 [2008-03-13 22:25 UTC] phpbugs at wayoverthere dot com
I'm still seeing the problem. I have recompiled PHP 
(php5.3-200803131930) on several different boxes - all Linux, but 
different distros (Ubuntu 7.10, openSuse 10.2, and a very old Gentoo 
box). On a hunch, I uninstalled the system PHP, thinking the custom 
PHP was using the system .so's. Same thing.

I even tried installing PHP on a Win2k box using the snapshot  
http://snaps.php.net/win32/php5.3-win32-200803132030.zip. I used the 
recommended php.ini file as a base config file, but enabled 
php_pdo.dll, php_pdo_mysql.dll, and php_pdo_sqlite.dll extensions. 
Then I created test.php and put this in it:

<?php
class test extends PDO {
    function __call($name, array $args) {
        echo "Called $name in ".__CLASS__.'<br>';
    }
    function foo() {
        echo "Called foo in ".__CLASS__.'<br>';
    }
}

$sqlite = new test('sqlite::memory:');
$sqlite->foo();
$sqlite->bar();

$mysql = new test('mysql:dbname=foo;host=10.1.1.142','foo','bar');
$mysql->foo();
$mysql->bar();

?>

Running "php test.php" gives:

Called foo in test<br>Called bar in test<br>Called foo in 
test<br>Fatal error: Call to undefined method test::bar() in C:
\php5\test.php on line 17
 [2008-03-14 06:07 UTC] crrodriguez at suse dot de
Works for me as well, with current 5_3 CVS
 [2008-03-15 19:34 UTC] phpbugs at wayoverthere dot com
Can someone confirm/deny this bug using the Windows binary version as 
I did? At least that way there's no compiling issues to complicate 
things.

Also, I poked around cvs.php.net and found what I think is the fix 
for #43663:

http://cvs.php.net/viewvc.cgi/php-src/ext/pdo/pdo_dbh.c?r1=1.82.2.31.2.17.2.2&r2=1.82.2.31.2.17.2.3

I checked my local 5.3 snapshot and it does have those added lines.
 [2008-03-29 16:45 UTC] phpbugs at wayoverthere dot com
I have compiled directly from a CVS checkout (PHP_5_3) on openSuse 
10.2, and I still see this problem. Is there anything I can do to 
convince someone that this bug actually exists? I don't understand 
how I'm the only one who can reproduce it, when I can reproduce it 
anywhere I test it - even using the precompiled Windows snapshots.

I followed the instructions on compiling from CVS (meaning compiling 
all the specific version requirements of autoconf, etc. and running 
buildconf), and used these configure options:

./configure --prefix=/home/shared/php5cvs/ --with-zlib --with-mysql=shared --enable-pdo=shared --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-sqlite=shared

My php.ini:
extension=pdo.so
extension=pdo_mysql.so
extension=pdo_sqlite.so

Running this test script:
<?php
class test extends PDO {
    function __call($name, array $args) {
        echo "Called $name in ".__CLASS__.'<br>';
    }
    function foo() {
        echo "Called foo in ".__CLASS__.'<br>';
    }
}

$sqlite = new test('sqlite::memory:');
$sqlite->foo();
$sqlite->bar();

$mysql = new test('mysql:dbname=test;host=localhost','root','');
$mysql->foo();
$mysql->bar();

?>

Gives:
Called foo in test<br>Called bar in test<br>Called foo in test<br>
Fatal error: Call to undefined method test::bar() 
in /home/shared/php5cvs/test.php on line 17

If necessary, I might be able to provide ssh access to one of the 
boxes I'm seeing this on.
 [2008-09-16 23:37 UTC] johannes@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 17:01:54 2014 UTC