In PHP 5, what is the difference between using self and $this?
When is each appropriate?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Short Answer
Full Answer
Here is an example of correct usage of
$thisandselffor non-static and static member variables:Here is an example of incorrect usage of
$thisandselffor non-static and static member variables:Here is an example of polymorphism with
$thisfor member functions:Here is an example of suppressing polymorphic behaviour by using
selffor member functions:From http://www.phpbuilder.com/board/showthread.php?t=10354489:
By http://board.phpbuilder.com/member.php?145249-laserlight