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 6390111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:29:11+00:00 2026-05-25T03:29:11+00:00

When I see a ‘self’ automatically to think of static methods. Lately I have

  • 0

When I see a ‘self’ automatically to think of static methods. Lately I have been pointed out that self depends on the context. Just like ‘parent’, which can also call static methods. Consider this example:

error_reporting(-1);

class A
{
    public $var = 1;

    public function __construct($n)
    {
        $this->var = $n;

        self::foo();
    }

    public function foo()
    {
        echo $this->var;
    }
}

$obj = new A(5);

Operate without errors and within the method foo $ this is available.
Someone can tell me some guide that explains in detail how the calls are resolved by self and parent?

  • 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-25T03:29:11+00:00Added an answer on May 25, 2026 at 3:29 am

    $this $is a reference to the current object, while self is the reference to the class where it is used.

    An example – the result of the code below is: (B::func)(A::func).

    class A {
        function call() {
            $this->func();
            self::func();
        }
    
        function func() {
            echo '(A::func)';
        }
    }
    
    class B extends A {
        function func() {
            echo '(B::func)';
        }
    }
    
    $b = new B();
    $b->call();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SEE EDIT UPDATES BELOW. Original question has been modified! I have a working window
See this question . It turns out that even without committing the transaction manually,
See the question. I want to see the methods and classes offered by a
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
See: http://jsbin.com/ebudec/edit#javascript,html It seems strange but I think jsBin doesn't recognize the jQuery document
see this link...: Exemple on this site i have this code <body> <div id=geral>
See the code below. Why does accessing [self.objects count] throw this error, when the
See,I have this code: template<typename T=int>struct color { T red, green, blue; color(T r,
SEE LIVE MENU HERE. I am trying to figure out why the drop-down disappears
See Diff 1.0 vs 2.0 . That one is solved, but it is still

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.