php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46761 get_class_vars includes protected variables depending on calling context
Submitted: 2008-12-05 13:46 UTC Modified: 2008-12-08 11:31 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phpbug dot classvars at sub dot noloop dot net Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.7 OS: Linux
Private report: No CVE-ID: None
 [2008-12-05 13:46 UTC] phpbug dot classvars at sub dot noloop dot net
Description:
------------
PHP 5.2.7 seems to have introduced a regression in get_class_vars(); depending on the calling context protected variables may be included in the result. 

This looks very similar to bug 45862 (which was closed in August with a comment saying fix committed to CVS 5.2, 5.3 and HEAD).

This build (built from source from today's release) produces "actual result":
PHP 5.2.7 (cli) (built: Dec  5 2008 12:39:40) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

This build (built from source from 5.2.6 release) produces "expected result":
PHP 5.2.6 (cli) (built: May 22 2008 10:18:33) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies


Reproduce code:
---------------
<?php
  abstract class Absclass {
    protected $v_protected;
    private $v_private;
    protected static function testIt($className) {
      var_dump(get_class_vars($className));
    }
  }

  class Testclass extends Absclass {
    public $v_public_sub;
    public static function init() {
      self::testIt('Testclass');
    }
  }

  $a = new Testclass();
  Testclass::init();
  var_dump(get_class_vars('Testclass'));


Expected result:
----------------
array(1) {
  ["v_public_sub"]=>
  NULL
}
array(1) {
  ["v_public_sub"]=>
  NULL
}


Actual result:
--------------
array(2) {
  ["v_public_sub"]=>
  NULL
  ["v_protected"]=>
  NULL
}
array(1) {
  ["v_public_sub"]=>
  NULL
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-08 11:31 UTC] jani@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

Yes, now it's consistent. When your use get_class_vars() in that context, the properties are available to it. No bug here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 11 02:00:01 2025 UTC