Dynamic Attribute ProblemProgramThe solution is as follows:
From: http://bbs.php100.com/read-htm-tid-25526.html
<? PHP Class Testclass { Private $ Va ; Private $ VB ; Private $ VC ; Private $ Allvars ; Public Function _ Construct (){ Echo 'Testclass _ construct '.' </BR>' ; // $ This-> Va = 1; $ This -> Getallvars ();} Public Function _ Get ( $ Name ){ Return $ This -> $ Name ;} Public Function _ Set ( $ Name , $ Value ){ Foreach ( $ This -> Allvars As $ Key ){ If ( $ Name =" $ Key " ){ $ This -> $ Name = $ Value ; Return ;}} Throw New Exception ('You have accessed undefined properties' );} Private Function Getallprops (){ $ R = New Reflectionclass ( $ This ); Return ( $ R -> Getproperties ());} Private Function Getallvars (){ $ Classprops = $ This -> Getallprops (); Foreach ( $ Classprops As $ Key ){ $ Temparr = Get_object_vars ( $ Key ); $ This -> Allvars []. = $ Temparr ['Name' ] ;}}} $ RC = New Testclass (); $ RC -> Va = 5 ; $ RC -> VB = 5 ; $ RC -> Vc = 5 ; $ RC -> Vd = 6 ; ?>