php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30408 get_object_vars()
Submitted: 2004-10-12 11:03 UTC Modified: 2004-10-16 22:18 UTC
From: guth at fiifo dot u-psud dot fr Assigned: helly (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.0.2 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: guth at fiifo dot u-psud dot fr
New email:
PHP Version: OS:

 

 [2004-10-12 11:03 UTC] guth at fiifo dot u-psud dot fr
Description:
------------
I got another strange behaviour with classes functions.

get_class_methods(Object $obj) returns private and protected methods. get_class_vars(string $class) returns private and protected properties.
However, get_object_vars() doesn't.

This method takes an Object parameter and I think that its behaviour should be the same as get_class_methods(Object $obj).

This bug is "related" to bug #30381.

Reproduce code:
---------------
<?php
class A {
	
	protected $plip;
	
	private function run() {
		
	}

}

class B extends A {
}

class hariCow extends B {

	private $plop = 'beta';

}

$db = new hariCow;

var_dump(get_class_vars('hariCow'));
var_dump(get_object_vars($db));

var_dump(get_class_methods($db));

echo $db->run();
?>

Expected result:
----------------
array(2) { ["plop"]=>  string(4) "beta" ["plip"]=>  NULL } array(2) { ["plop"] => ... ["plip"] => ... }
array(1) { [0]=>  string(3) "run" } 

Actual result:
--------------
array(2) { ["plop"]=>  string(4) "beta" ["plip"]=>  NULL } array(0) { }
array(1) { [0]=>  string(3) "run" } 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-12 11:16 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip
 [2004-10-16 17:28 UTC] guth at fiifo dot u-psud dot fr
I get :

array(0) { } array(0) { } array(0) { }

I think it's the best solution to print only public properties and methods for this cases.

I saw that get_object_vars($this) prints private/protected properties, which is the best solution too.

So works fine in 5.1.0-dev..

What will you do for the 5.0.* branch ?
 [2004-10-16 21:21 UTC] helly@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

%.0.3-dev and 5.1.0-dev aka HEAD should behave in the same way, no protected, private vars unless called from that scope. Please verify.
 [2004-10-16 21:57 UTC] guth at fiifo dot u-psud dot fr
I test the function with different values and it seems to work fine.

Thank you.
 [2004-10-16 22:18 UTC] johannes@php.net
works now -> close bug 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 11:01:32 2024 UTC