|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-08-23 04:42 UTC] requinix@php.net
-Status: Open
+Status: Suspended
-Package: MSSQL related
+Package: sqlsrv
[2016-08-23 04:42 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 00:00:01 2025 UTC |
Description: ------------ When a custom classname is passed to sqlsrv_fetch_object, the constructor is called in a static context, causing an error if it does anything with $this. This is inconsistent with the context used by PDO and Mysqli drivers. The problem occurs with driver version SQLSRV40.EXE under IIS 8.5. If you stick a print_r(debug_backtrace()) in the __construct() method of the custom class, you can see its type is '::' with sqlsrv_fetch_object instead of '->' for PDO->fetchObject or mysqli_fetch_object. Test script: --------------- <?php class Foo { protected $foo = null; public function __construct() { $this->foo = "bar"; } } $conn = sqlsrv_connect( 'HOSTNAME', ["Database"=> 'DATABASE', "UID"=> 'USERNAME', "PWD"=>'PASSWORD']); $stmt = sqlsrv_query($conn, "SELECT * FROM SOME_TABLE"); try { while ($obj = sqlsrv_fetch_object($stmt, 'Foo')) ; } catch (Error $e) { print_r($e); } Expected result: ---------------- There should be no output. Actual result: -------------- Error Object ( [message:protected] => Using $this when not in object context [string:Error:private] => [code:protected] => 0 [file:protected] => W:\path\to\wwwroot\test\db.php [line:protected] => 6 [trace:Error:private] => Array ( [0] => Array ( [function] => __construct [class] => foo [type] => :: [args] => Array ( ) ) [1] => Array ( [file] => W:\path\to\wwwroot\test\db.php [line] => 12 [function] => sqlsrv_fetch_object [args] => Array ( [0] => Resource id #3 [1] => foo ) ) ) [previous:Error:private] => )