php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30659 get_class_vars() works incorrect
Submitted: 2004-11-02 12:45 UTC Modified: 2004-11-08 11:13 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mx at tut dot by Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2004-11-02 (dev) 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: mx at tut dot by
New email:
PHP Version: OS:

 

 [2004-11-02 12:45 UTC] mx at tut dot by
Description:
------------
behavior of get_class_vars() changed between 13 Sep 2004 and 22 Oct 2004. Is it correct?

Reproduce code:
---------------
<?

class A {
	private $user;
	protected $group;
	public $world;

	function dump() {
		print_r(get_object_vars($this));
	}
}

class B extends A {
	public $zoo;
}

$a = new B();
print_r(get_class_vars(get_class($a)));
print_r(get_object_vars($a));
$a->dump();

?>

Expected result:
----------------
Array ( [zoo] => [group] => [world] => )
Array ( [zoo] => [group] => [world] => )
Array ( [zoo] => [group] => [world] => )

Actual result:
--------------
Array ( [zoo] => [world] => ) 
Array ( [zoo] => [world] => ) 
Array ( [zoo] => [group] => [world] => )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-03 01:01 UTC] helly@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.

One you get correct Acutal/Expected info come back.
 [2004-11-08 02:03 UTC] aaron at visualprose dot com
You can download a script that will reproduce this bug 
here: http://visualprose.com/inheritance-bug.php.gz .  I 
am experiencing this on Mac OS X 10.3.5 (client and 
server) under PHP 5.0.2.  This bug wasn't occuring under 
PHP 5.0.0.  Let me know if you need more info.

     <:> Aaron Jensen
     <:> aaron@visualprose.com
 [2004-11-08 11:13 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

get_class_vars($this) returns the name of the derived class B where $one is defined. You access the properties from class A. Since private properties are only visible to the defining class - in this case B - the error is correct.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 14:01:29 2024 UTC