You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a custom classname is passed to sqlsrv_fetch_object, the constructor is called in a static context, causing an error if the constructors attempts to manipulate $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);
}
Description:
When a custom classname is passed to sqlsrv_fetch_object, the constructor is called in a static context, causing an error if the constructors attempts to manipulate $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:
Expected result:
There should be no output.
Actual result:
The text was updated successfully, but these errors were encountered: