Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Difference between self and this keyword in PHP

General discussions related to php

Moderators: macek, egami, gesf

Difference between self and this keyword in PHP

Postby phpkiller » Sun Dec 08, 2013 11:36 pm

As we are using OOPS concepts here are the difference:-

-self refers to the current class
-self can be used to call static functions and reference static
member variables
-self can be used inside static functions
-self can also turn off polymorphic behavior by bypassing
the vtable
-$this refers to the current object
-$this can be used to call static functions
-$this should not be used to call static member
variables. Use self instead.
-$this can not be used inside static functions
phpkiller
New php-forum User
New php-forum User
 
Posts: 31
Joined: Thu Jun 28, 2012 2:11 pm

Re: Difference between self and this keyword in PHP

Postby madjamesiam » Mon Dec 23, 2013 2:34 am

$this = current object, refers current object
$self = current class, refers current class it used to calling class of objects
Clement crazy
connected commerce
madjamesiam
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Dec 23, 2013 2:13 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron