php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #17537 get_class_vars works unexpected
Submitted: 2002-05-30 21:08 UTC Modified: 2004-02-22 14:54 UTC
Votes:3
Avg. Score:3.3 ± 1.2
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: nandi-nospam1 at harem dot dev dot hu Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.2.1 OS: Linux 2.4.
Private report: No CVE-ID: None
 [2002-05-30 21:08 UTC] nandi-nospam1 at harem dot dev dot hu
The documentation says that the get_class_vars() method should return an array only with the properties wich had DEFAULT values already at class definition. That worked fine with PHP 4.1.2 but it's behavior changed with PHP 4.2.[0 or 1] because it displays also those properties which has no default values at definition. I don't really think that this is a bug, but it seems that there was a change in the function behavior and neither the changelog nor the documentation mentions a word about this change.


Example - the following script from the docs:

<?php

class myclass {

    var $var1; // this has no default value...
    var $var2 = "xyz";
    var $var3 = 100;
    
    // constructor
    function myclass() {
        return(true);
    }

}

$my_class = new myclass();

$class_vars = get_class_vars(get_class($my_class));
echo "<pre>";
foreach ($class_vars as $name => $value) {
    echo "$name : $value\n";
}
echo "</pre>";

?>

should outuput something like this:
var2 : xyz
var3 : 100


but the result in PHP 4.2.1 is:
var1 : 
var2 : xyz
var3 : 100


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-31 02:45 UTC] derick@php.net
Reclassify as doc problem
 [2002-11-15 04:41 UTC] philip@php.net
This is now documented.  The change can be seen in here:

http://cvs.php.net/cvs.php/phpdoc/en/reference/classobj/functions/get-class-vars.xml

As of PHP 4.2.0, all are shown.


 [2004-02-22 14:53 UTC] mrbrush at harem dot dev dot hu
The documentation says that the get_class_vars() method should return an
array only with the properties wich had DEFAULT values already at class
definition. That worked fine with PHP 4.1.2 but it's behavior changed
with PHP 4.2.[0 or 1] because it displays also those properties which
has no default values at definition. I don't really think that this is a
bug, but it seems that there was a change in the function behavior and
neither the changelog nor the documentation mentions a word about this
change.

Example - the following script from the docs:

<?php

class myclass {

    var $var1; // this has no default value...
    var $var2 = "xyz";
    var $var3 = 100;
    
    // constructor
    function myclass() {
        return(true);
    }

}

$my_class = new myclass();

$class_vars = get_class_vars(get_class($my_class));
echo "<pre>";
foreach ($class_vars as $name => $value) {
    echo "$name : $value\n";
}
echo "</pre>";

?>

should outuput something like this:
var2 : xyz
var3 : 100

but the result in PHP 4.2.1 is:
var1 : 
var2 : xyz
var3 : 100
 [2004-02-22 14:54 UTC] nandi-nospam1 at harem dot dev dot hu
The documentation says that the get_class_vars() method should return an
array only with the properties wich had DEFAULT values already at class
definition. That worked fine with PHP 4.1.2 but it's behavior changed
with PHP 4.2.[0 or 1] because it displays also those properties which
has no default values at definition. I don't really think that this is a
bug, but it seems that there was a change in the function behavior and
neither the changelog nor the documentation mentions a word about this
change.

Example - the following script from the docs:

<?php

class myclass {

    var $var1; // this has no default value...
    var $var2 = "xyz";
    var $var3 = 100;
    
    // constructor
    function myclass() {
        return(true);
    }

}

$my_class = new myclass();

$class_vars = get_class_vars(get_class($my_class));
echo "<pre>";
foreach ($class_vars as $name => $value) {
    echo "$name : $value\n";
}
echo "</pre>";

?>

should outuput something like this:
var2 : xyz
var3 : 100

but the result in PHP 4.2.1 is:
var1 : 
var2 : xyz
var3 : 100
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 19 18:00:02 2025 UTC