Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 1.05 KB

06_static_props_and_methods.md

File metadata and controls

71 lines (49 loc) · 1.05 KB

class Static methods & properties

Classes can have Static methods or properties. The static means that for using them we not need to create a object from them and we can use them directly on class.

For example:

class Person
    $static_prop = 'the static prop'

    func some_static_method
        println('the static method')
    endfunc
endclass

println(Person->static_prop)
Person->some_static_method()

output:

the static prop
the static method

The static properties and functions are EVENT LIKE normal declaration of them.

Also they can recive the value:

class Person
    $someprop = 'hello world'
endclass

println(Person->someprop)

Person->someprop = 'new value'

println(Person->someprop)

output:

hello world
new value

Also they are accessible in objects:

class Person
    $static_prop

    func show_static_prop
        println('value: ' + $this->static_prop)
    endfunc
endclass

Person->static_prop = 'hello world'

$p = Person()

$p->show_static_prop()

output:

value: hello world