php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28765 get_object_vars returns blank array for a mysqli object
Submitted: 2004-06-14 02:49 UTC Modified: 2004-06-14 20:17 UTC
From: chall5 at tampabay dot rr dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.0RC3 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chall5 at tampabay dot rr dot com
New email:
PHP Version: OS:

 

 [2004-06-14 02:49 UTC] chall5 at tampabay dot rr dot com
Description:
------------
using get_object_vars() on a mysqli object returns an empty array.  As I am able to access vars such as host_info via $mysqliObj->host_info, i would expect this to be a public var, which I would expect to be returned from get_object_vars($mysqliObj).  to test this, i defined a test class with a public var, a private var, and a protected var.  after instatiating the class an setting each of the vars to a string value, i called get_object_vars() on the object and as expected, only the public var was returned in the array from the function.

I also tested get_class_methods() and get_class_vars() on the mysqli object.  get_class_methods() does return an array of method names.  get_class_vars() returns an empty array.  these tests are NOT included in the attached code.

Reproduce code:
---------------
<?php
class testClass {
	public $a;
	private $b;
	protected $c;
	public function test() {
		$this->a = "a";
		$this->b = "b";
		$this->c = "c";
	}
}

$mysqli = new mysqli("localhost", "root", "vnbeRTC", "mysql");
echo "mysqli class:\n";
echo "host info: ".$mysqli->host_info."\n\n";  // direct access, public var???
echo "get_object_vars(\$mysqli)\n";
print_r(get_object_vars($mysqli)); // prints empty array
$mysqli->close();
echo "\ntestClass class:\n";
$test = new testClass;
$test->test();
echo "get_object_vars(\$test)\n";
print_r(get_object_vars($test)); // prints public vars only (expected)
print_r(get_class_vars($test)); // strange output for protected var name
?>

Expected result:
----------------
array returned from get_object_vars() on a mysqli object would return an array containing all public vars in the object.

Actual result:
--------------
the returned array was empty.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-14 02:52 UTC] chall5 at tamapbay dot rr dot com
and yes, i know i left my root mysql password in the code.  its on a non-networked dev box, so it doesn't matter.
 [2004-06-14 14:13 UTC] chall5 at tampabay dot rr dot com
correcting my email address
 [2004-06-14 20:17 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Overloaded classes (like mysqli) handle some of their members virtual. That means they do not give you direct read or write access nor do they publish those members.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 14:01:29 2024 UTC