kohana/database — pull request #74 by kwhat (2014-06-07 16:52:51+00:00)
Title: Passing NULL to argument 3 of mysql_fetch_object has undefined behavior.

Hi @enov,

mysql_fetch_object($result, $as_object, NULL) does behaves differently than mysql_fetch_object($result, $as_object); on PHP 5.3 and 5.5. The problem is somewhere in the way PHP constructs classes, not the mysql function itself. I would love to give you functional example but its going to take a bit of code so I will kind of prototype out what I am getting at.

Lets assume we are working with the following ADT, Model_DataType is simply an empty interface.

class Model_Repository_DataType_Account implements Model_DataType {
public $id;
public $department;
public $contractor;
public $username;
public $password;
public $firstname;
public $lastname;
public $email;
public $groups;
}

If you called mysql_fetch_object($result, 'Model_Repository_DataType_Account', NULL) on PHP 5.5, everything works as expected, however, if you are using PHP 5.3, you will be greeted with this obscure error: "Class Model_Repository_DataType_Account does not have a constructor hence you cannot use ctor_params" due to the lack of a public __construct() { ... } method. Adding that method results in functional behavior with the no-arg constructor being called. Using mysql_fetch_object($result, 'Model_Repository_DataType_Account') on PHP 5.3 or 5.5 results in the expected behavior.

I wasn't sure if was possible to change the old pull request, so please close #73 in favor of this one. Thanks again for addressing this.