From 1faa210cc4be9a3c8f16a4c72440be4d7d8c1e31 Mon Sep 17 00:00:00 2001 From: Xaver Loppenstedt Date: Tue, 6 Sep 2016 23:36:56 +0200 Subject: [PATCH] Fix sqlsrv_fetch_object modifies full qualified class names --- source/sqlsrv/stmt.cpp | 1 - source/sqlsrv/tests/bug_119.phpt | 50 ++++++++++++++++++++++++++++++++ source/sqlsrv/tests/config.inc | 6 ++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 source/sqlsrv/tests/bug_119.phpt create mode 100644 source/sqlsrv/tests/config.inc diff --git a/source/sqlsrv/stmt.cpp b/source/sqlsrv/stmt.cpp index 830b042f5..e1b2fc769 100644 --- a/source/sqlsrv/stmt.cpp +++ b/source/sqlsrv/stmt.cpp @@ -796,7 +796,6 @@ PHP_FUNCTION( sqlsrv_fetch_object ) } class_name = Z_STRVAL( *class_name_z ); class_name_len = Z_STRLEN( *class_name_z ); - zend_str_tolower( class_name, class_name_len ); } if( ctor_params_z && Z_TYPE_P( ctor_params_z ) != IS_ARRAY ) { diff --git a/source/sqlsrv/tests/bug_119.phpt b/source/sqlsrv/tests/bug_119.phpt new file mode 100644 index 000000000..207c081ca --- /dev/null +++ b/source/sqlsrv/tests/bug_119.phpt @@ -0,0 +1,50 @@ +--TEST-- +Bug #119 (sqlsrv_fetch_object modifies full qualified class names) +--SKIPIF-- + +--INI-- +--FILE-- + $database, 'Uid' => $username, 'PWD' => $password]); +print 'sqlsrv connection successfull: '.($conn !== false ? 'yes' : 'no').PHP_EOL; + +$idx = array_search(__NAMESPACE__.'\\A',get_declared_classes()); +echo "BEFORE sqlsrv_fetch_object - "; +echo "orig class ".__NAMESPACE__.'\\A'." exits: ".(class_exists(__NAMESPACE__.'\\A')?'yes':'no').PHP_EOL; +echo "BEFORE sqlsrv_fetch_object - "; +echo "lower class ".strtolower(__NAMESPACE__.'\\A')." exits: ".(class_exists(strtolower(__NAMESPACE__.'\\A'))?'yes':'no').PHP_EOL; +echo "BEFORE sqlsrv_fetch_object - "; +echo 'full qualified class name: '.get_declared_classes()[$idx].PHP_EOL; + +$stmt = sqlsrv_query($conn, "SELECT 'foo' as tname"); +print 'sqlsrv query successfull: '.($stmt !== false ? 'yes' : 'no').PHP_EOL; + +$obj = sqlsrv_fetch_object($stmt, __NAMESPACE__.'\\A'); + +echo "AFTER sqlsrv_fetch_object - "; +echo "orig class ".__NAMESPACE__.'\\A'." exits: ".(class_exists(__NAMESPACE__.'\\A')?'yes':'no').PHP_EOL; +echo "AFTER sqlsrv_fetch_object - "; +echo "lower class ".strtolower(__NAMESPACE__.'\\A')." exits: ".(class_exists(strtolower(__NAMESPACE__.'\\A'))?'yes':'no').PHP_EOL; +echo "AFTER sqlsrv_fetch_object - "; +echo 'full qualified class name: '.get_declared_classes()[$idx].PHP_EOL; +sqlsrv_free_stmt($stmt); +echo 'object has the correct value: '.$obj->tname.PHP_EOL; +?> +--EXPECT-- +sqlsrv connection successfull: yes +BEFORE sqlsrv_fetch_object - orig class Tests\A exits: yes +BEFORE sqlsrv_fetch_object - lower class tests\a exits: yes +BEFORE sqlsrv_fetch_object - full qualified class name: Tests\A +sqlsrv query successfull: yes +AFTER sqlsrv_fetch_object - orig class Tests\A exits: yes +AFTER sqlsrv_fetch_object - lower class tests\a exits: yes +AFTER sqlsrv_fetch_object - full qualified class name: Tests\A +object has the correct value: foo diff --git a/source/sqlsrv/tests/config.inc b/source/sqlsrv/tests/config.inc new file mode 100644 index 000000000..883b5bfec --- /dev/null +++ b/source/sqlsrv/tests/config.inc @@ -0,0 +1,6 @@ +