Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sqlsrv_fetch_object modifies full qualified class names #147

Merged
merged 1 commit into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion source/sqlsrv/stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
50 changes: 50 additions & 0 deletions source/sqlsrv/tests/bug_119.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
Bug #119 (sqlsrv_fetch_object modifies full qualified class names)
--SKIPIF--
<?php if(!extension_loaded("sqlsrv")) print "skip"; ?>
--INI--
--FILE--
<?php
namespace Tests;

class A {
public $tname;
}

require('config.inc');

$conn = sqlsrv_connect($serverName, ['Database' => $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
6 changes: 6 additions & 0 deletions source/sqlsrv/tests/config.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
$serverName = getenv('MSSQL_SERVERNAME') ?: 'localhost';
$database = getenv('MSSQL_DATABASE') ?: 'test_db';
$username = getenv('MSSQL_USERNAME') ?: 'test_user';
$password = getenv('MSSQL_PASSWORD') ?: 'test_pass';