Call an object method: Difference between revisions

(Add Zig example)
Line 1,495:
say $object.&example-method; # Outputs "This is a string."
</lang>
 
=={{header|Phix}}==
Class methods are only "static" (not really a Phix term) if you don't override them.<br>
Phix does not demand that all routines be inside classes; traditional standalone routines are "static" in every sense.<br>
There is no way to call a class method without an instance, since "this" will typecheck even if not otherwise used.
Needs 0.8.1+
<lang Phix>class test
string msg = "this is a test"
procedure show() ?this.msg end procedure
procedure inst() ?"this is dynamic" end procedure
end class
test t = new()
t.show() -- prints "this is a test"
t.inst() -- prints "this is dynamic"
t.inst = t.show
t.inst() -- prints "this is a test"</lang>
 
=={{header|PHP}}==
7,806

edits