|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-23 12:38 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 02:00:01 2025 UTC |
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.