Powered By Blogger

Sunday, 31 July 2011

"this" or "self" keyword

Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members.

<?phpclass X {
    
private $non_static_member = 1;
    
private static $static_member = 2;

    function
__construct() {
        echo
$this->non_static_member . ' '
           
. self::$static_member;
    }
}

new
X();?> 

No comments:

Post a Comment