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 this image or here http://cl.ly/image/0a2R2V0C1y2l We have a div that uses this image
See title. That's all I have to ask. The net doesn't have many succinct
see fiddle Firstly i am new to jquery. i have to make one cell
see fiddle i have html table and one textbox and one button.make cell selection
see jsbin if u seen my jsbin then i have two table hardcode table
See http://www.sitepen.com/blog/2008/06/17/json-referencing-in-dojo/ for how it's used in dojo. I'm looking for libraries that can
See also: Where in the documentation does it say that while tests readdir for
See subject. What were they thinking? UPDATE: Changed from static to internal linkage to
See code: class Foo { public static function dumpObj($obj) { var_dump($obj); } } class
See this question . Except that the answer returns the child element when a

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.