Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1030091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:38:45+00:00 2026-05-16T12:38:45+00:00

In plain English, how is $this used in PHP? It’s such a simple concept

  • 0

In plain English, how is $this used in PHP?

It’s such a simple concept to me in JavaScript, but for some reason in PHP I can’t get my head around this variable and its function. What, at any given point, is it referring to exactly? I have only tertiary experience with OOP, and I suspect that’s why it’s hard for me to understand its usage, but I’m trying to get better, and a lot of the code I examine uses this variable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:38:46+00:00Added an answer on May 16, 2026 at 12:38 pm

    In Very Simple English:

    Once inside an object’s function, you have complete access to its variables, but to set them you need to be more specific than just using the variable name you want to work with. To properly specify you want to work with a local variable, you need to use the special $this variable, which PHP always sets to point to the object you are currently working with.

    For example:

    function bark()
    {
        print "{$this->Name} says Woof!\n";
    } 
    

    Whenever you are inside a function of an object, PHP automatically sets the $this variable contains that object. You do not need to do anything to have access to it.


    In Normal English:

    $this is a pseudo-variable which is available when a method is called from within an object context. It is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object)

    An example:

    <?php
    class A
    {
        function foo()
        {
            if (isset($this)) {
                echo '$this is defined (';
                echo get_class($this);
                echo ")\n";
            } else {
                echo "\$this is not defined.\n";
            }
        }
    }
    
    class B
    {
        function bar()
        {
            // Note: the next line will issue a warning if E_STRICT is enabled.
            A::foo();
        }
    }
    
    $a = new A();
    $a->foo();
    
    // Note: the next line will issue a warning if E_STRICT is enabled.
    A::foo();
    $b = new B();
    $b->bar();
    
    // Note: the next line will issue a warning if E_STRICT is enabled.
    B::bar();
    ?>
    

    Output:

    $this is defined (A)
    $this is not defined.
    $this is defined (B)
    $this is not defined.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In plain English this is the jQuery functionality i'm after: I need to get
I am using plain JavaScript on my project. How can I get the value
in plain english can you please explain to me what does this line mean:
Can someone explain in plain english the syntax of this: Here is the signature
Plain and simple issue: I would like to annotate my method parameter with some
Given this plain JavaScript construct: var MyObject = function() { var privateArray = [
Possible Duplicate: Plain english explanation of Big O I'd imagine this is probably something
Can someone explain in plain english what is SOA all about ? I hear
In plain English, this code kicks in when an element is hovered over. When
I'm using plain English here. I've got this great app with multiple tabs and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.