oop - PHP ignoring __set method inside the class -


I am building a class with many assumptions, and I have decided to put them in the __set method ( I'm not sure it's a good form because I have limited OOP experience). It works fine, throws the proper errors when invalid values ​​are passed from outside the class, however, if one variable is modified in the class then the _ _set method is first ignored.

Any insights will be highly appreciated

  // RESULT :::: ::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // PASS: test exception handling // __SET : B to 123 / Pass: Test with Valid Values: 123 // FAIL: Test Exception Handling World 2 & lt ;? Php square test {public $ a; Private $ B; Function __set ($ key, $ val) {switch ($ key) {case 'b': if (! Is_numeric ($ val)) new exception throw ("should be variable $ b numeric"); break; } Echo ("__SET: {$ key} to set {$ val} 
); $ This- & gt; $ Key = $ val; } Function __get ($ key) {return $ this- & gt; $ Key; } Function bMethod () {$ this- & gt; B = "World2"; }} $ T = new test (); // Try one {$ t-> A = "hello"; Echo "PASS: $ a: $ {->} hold (exception $ E) {echo" failed: test $ A ";} // test b {$ t-> gt; b =" world "; echo" failed: Trial $ B Exception Handling & lt; Br / & gt; ";} catch (exception $ e) {resonated" pass: trial $ B exception handling & lt; Valid values ​​with {$ t-> gt; b = 123; echo '} // test b; PASS: Test $ B with valid value: {$ t-> B} & lt; Try the {$ t-> bMethod ("World") except for the exception handling with the grip (exception $ E) {echo "failure: test $ B";} // ; Echo "failed: test $ B exception handling {$ t-> B} & lt; Br / & gt; ";} catch (exception $ e) {resonated" pass: trial $ B exception handling & lt; Read the definition of "__set": "__set () is played while writing data"}

Inaccessible member. "The unavailable key is here from within the classroom, all members are accessible and bypassed __set.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -