I was in a problem with static variables / methods while dealing with legacy codes Reads:
& lt; Php square testbase {public stable $ value; Public static work addValue ($ value) {static :: $ value [] = $ value; }} Enhances the class teston testbase {} class test to two testbase {} teston :: adw ('a'); TestOne :: addvalue ('two'); TestOne :: addvalue ('three'); Var_dump (TestOne :: $ value); Echo "
< TestTwo :: addvalue ('four'); TestTwo :: addvalue ('Five'); TestTwo :: addvalue ('six'); Var_dump (TestTwo :: $ value); Echo "
< Var_dump (TestOne :: $ value); ? & Gt; This generates the output:
array (3) {[0] = & gt; String (3) "One" [1] = & gt; String (3) "two" [2] = & gt; String (5) "three"}
array (6) {[0] = & gt; String (3) "One" [1] = & gt; String (3) "two" [2] = & gt; String (5) "three" [3] = & gt; String (4) "Four" [4] = & gt; String (4) "Five" [5] = & gt; String (3) "six"}
array (6) {[0] = & gt; String (3) "One" [1] = & gt; String (3) "two" [2] = & gt; String (5) "three" [3] = & gt; String (4) "Four" [4] = & gt; String (4) "Five" [5] = & gt; As you can see, any value added to both has been added as the string (3) "six"}
. It was my understanding that static :: connects the methods to the class of inherited classes, not the parent category, so I am thinking that it is generated by the fact that only a constant :: $ value will be created and Both assume that I'm referring to the value. It can be decided by declaring public static values on all those sections which are spread over the base, but there is an easy way to do that each gets their steady copy? Any keywords or tricks that will stop the need to reclaim on each successor class?
I am thinking that it arises from the fact that only one constant :: $ Values will be created anytime and both will assume that I am referring to that value.
Correct.
This can be decided by declaring public fixed $ values on all those sections which are extending from the base, but there is an easy way to do this that each one has its own stable Get the copy? Any keywords or tricks that will stop the need to redefine in each heritage class?
No, there is nothing like that, however, what is the trick to avoid as much as possible stuff. When you go into such a situation, then there is a good indication of the time that your code design needs some customization.
Comments
Post a Comment