Add a variable to a class instance at runtime: Difference between revisions

(Merge omitted languages at bottom and add Processing)
Line 1,282:
say 42.answer; # Life, the Universe, and Everything</lang>
This practice, though allowed, is considered to be Evil Action at a Distance.
 
=={{header|Phix}}==
Dynamic classes are really just wrappers to per-instance dictionaries, not entirely unlike Go/Kotlin/etc, but with slightly nicer syntax.<br>
Attempting to fetch/store "jelly" on a non-dynamic class would trigger a fatal error, unless said field had been explictly defined.
Needs 0.8.1+
<lang Phix>class wobbly dynamic
-- (pre-define a few fields/methods if you like)
end class
wobbly wobble = new()
?wobble.jelly -- 0
wobble.jelly = "green"
?wobble.jelly -- "green"</lang>
 
=={{header|PHP}}==
7,795

edits