#29774 [Opn->Bgs]: no string variable allowed in function get_class_vars and get_class_methods
ID: 29774
Updated by: tony2001@php.net
Reported By: rkressirer at t-online dot de
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: WIN2K
PHP Version: 5.0.0
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2004-08-20 22:02:19] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29774&edit=1
Thread (2 messages)