Skip to content

Latest commit

 

History

History
28 lines (26 loc) · 614 Bytes

File metadata and controls

28 lines (26 loc) · 614 Bytes

<-- Return to index

Instance reference

How are names referenced from within objects?

PHP

By use of the this keyword.

<?php
    class myClass {
        public $foo = 4;
        private $bar = 5;

        function baz() {
            echo $this->foo;
            echo $this->bar;
        }
    }
?>

Will echo both variables of the class, public and private. Private variables, however, cannot be accessed directly from outside of the objects namespace.

Python

By use of the self keyword.

class myClass:
    foo = 4
    def baz():
        print(self.foo)