php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50275 get_class_vars with protected members inconsistent
Submitted: 2009-11-23 20:03 UTC Modified: 2009-11-23 21:26 UTC
From: msa at xtivate dot de Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.11 OS: ubuntu
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: msa at xtivate dot de
New email:
PHP Version: OS:

 

 [2009-11-23 20:03 UTC] msa at xtivate dot de
Description:
------------
get_class_vars return is inconsistent.
from inside the class it returnes the protected members as well as the public.
from outside the class it returns only the public.

until php 5.2.10 it only returned the public, not the non-public.
(as is it specified in the documentation that it only returns the public...)


so... now it does not only return the non-public when called from inside the actual class, but is inconsistent with the output  that one gets calling outside of the class.

this is a _major issiue_ in terms of scoping/inheritance/consitency.


please change it back to the way it was before because that was 
a) consistent 
and
b) in accordance with the spec ( "only public" )




Reproduce code:
---------------
abstract class Vader{
	protected $vaders_protected_var;
}

class Luke extends Vader {
	public $lukes_public_var;	
	final function ShowVars(){
		echo "<br> inside Luke:<br>";
		print_r(get_class_vars(get_class($this)));
	}
}

$luke = new Luke();

$luke->ShowVars();

echo "<br> outside luke:<br>";
print_r( get_class_vars("Luke") );


Expected result:
----------------
inside Luke:
Array ( [lukes_public_var] => )
outside luke:
Array ( [lukes_public_var] => ) 

Actual result:
--------------
inside Luke:
Array ( [lukes_public_var] => [vaders_protected_var] => )
outside luke:
Array ( [lukes_public_var] => ) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-23 21:26 UTC] jani@php.net
It was fixed to be consistent and inside class defining the properties it is perfectly okay to show protected variables. Also, protected != hidden, do you agree? :) (further discussion -> internals@lists.php.net please)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC