php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6587 get_class_vars returns empty array
Submitted: 2000-09-07 01:39 UTC Modified: 2000-09-07 10:20 UTC
From: jon at webglow dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.2 OS: RedHat 6.2
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: jon at webglow dot com
New email:
PHP Version: OS:

 

 [2000-09-07 01:39 UTC] jon at webglow dot com
I have tried:

<?
class start_vars_list {
    var $first_name;
    var $last_name;
    var $company;
}

$vars = get_class_vars(start_vars_list);
echo $vars[1];

?>

$vars is an array, but contains no data. I was thinking that echo $vars[1];
should give me "last_name" but it does not return anything.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-07 02:09 UTC] waldschrott@php.net
well, if you don?t initialize your variable with some value, get_class_vars() won?t return anything

var $f='set';

will work,
anyway in the case of CLASSES it could make sense that variables that aren?t initialized and listed instead with

var $f;

are returned too, *but* that would require significant changes, or another function like get_unitialized_class_vars() or sth. else, because var_dump() cannot display something that is between NULL and sth.

I think this only can be turned into a feature request (if possible at all, not sure) using another function, or a parameter for the current function

comments anyone?
 [2000-09-07 10:07 UTC] jon at webglow dot com
Hmmm... Perhaps I am just missing something here, but the following does not return anything either:

<?
class start_vars_list { 

    var $first_name='1'; 
    var $last_name='2'; 
    var $company='3';
} 

$vars = get_class_vars(start_vars_list);
echo $vars[1];

?>
 [2000-09-07 10:09 UTC] andrei@php.net
Run var_dump($vars). See the result.
 [2000-09-07 10:11 UTC] stas@php.net
Please do var_dump to the result of get_class_vars and see how it is organized.
 [2000-09-07 10:20 UTC] waldschrott@php.net
did closing without comment imply variables without initialized value cannot be retrieved with another function OR it that it does not make sense?
 [2013-10-12 22:58 UTC] googleguy@php.net
Automatic comment from SVN on behalf of googleguy
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=331791
Log: Fixes bug #6587 - Missing third parameter in example

patch by dean at deansas dot org
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC