php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29774 no string variable allowed in function get_class_vars and get_class_methods
Submitted: 2004-08-20 22:02 UTC Modified: 2004-08-23 12:38 UTC
From: rkressirer at t-online dot de Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.0 OS: WIN2K
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: rkressirer at t-online dot de
New email:
PHP Version: OS:

 

 [2004-08-20 22:02 UTC] rkressirer at t-online dot de
Description:
------------
For to analyse objects the following function was written. According to the manual it should be possible to use a 'string class_name' as variable in the functions get_class_vars() and get_class_methods().
It turned out, that this is not the case. Only by replacing the variable (in this case 'KlassenName') by the function get_class($obj) the required result will be obtained.
The code shows both versions of each function and the respective Error Message.

(windows+apache1.x+php module version on localhost)

Reproduce code:
---------------
function object_structure($obj)
{
print ("Klasse: ".$KlassenName= (get_class($obj))."<br>");

$properties = (get_object_vars($obj)); 
while (list($prop, $val) = each($properties))
        echo "$prop = $val<br>";
//---------------------------------------------------------
//works:		
$stdClassVars = (get_class_vars(get_class($obj)));
while (list($prop) = each($stdClassVars))
        echo "Standardelement: $prop<br>";

//does not work: 
//Warning: Variable passed to each() is not an array or object in f:\programme\apache... 
$stdClassVars = (get_class_vars($KlassenName));
while (list($prop) = each($stdClassVars))
       echo "Standardelement: $prop<br>";			
//---------------------------------------------------------//works:		
$methods = (get_class_methods(get_class($obj)));
foreach ($methods as $method) print("Methode: ".$method."<br>");

//does not work:
//Warning: Invalid argument supplied for foreach() in f:\programme...
$methods = (get_class_methods($KlassenName));
foreach ($methods as $method) print("Methode: ".$method."<br>");
return;
}
?>

Expected result:
----------------
any existing class_variable or method of an object should be shown with both versions.
For testing I used:

class baugruppe{
public $BG_ID, $BG_NAME, $BG_NR='421500.000', $Version='d';
function __construct($BG_ID, $BG_NAME)
	{
	$this->BG_ID =$BG_ID;
	$this->BG_NAME=$BG_NAME;
	return;
	}
function show()
	{
	echo "$this->BG_ID<br>";
	echo "$this->BG_NR<br>";
	echo "$this->BG_NAME<br>";
	echo "$this->Version<br>";
	return;
	}
}	//end class
$transferarm= new baugruppe(3,'Transferarm');

Actual result:
--------------
only version marked with "works" shows results.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-23 12:38 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Operator "." has higher precedence, than "=", so $KlassenName becomes (get_class($obj))."<br>" instead of "get_class($obj)".
Just take out assignment from the string and you'll get expected results.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 28 23:01:27 2024 UTC