|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-06-14 02:52 UTC] chall5 at tamapbay dot rr dot com
[2004-06-14 14:13 UTC] chall5 at tampabay dot rr dot com
[2004-06-14 20:17 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 22:00:02 2025 UTC |
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.