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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:26:33+00:00 2026-06-10T20:26:33+00:00

In first case we called function in object context. In second case we have

  • 0

In first case we called function in object context. In second case we have class context.
Does parent:: work like this and self simultaneously depending on the context?

class par_parent{
    private $var='value1';
    private static $val='value2';
    public function call(){
        var_dump('Object '.$this->var);
    }
    public static function staticCall(){
        var_dump('Static '.self::$val);
    }
}

class par_child extends par_parent{
    public function callObj(){
        parent::call();
    }

    public static function callStatic(){
        parent::staticCall();
    }
}



$obj=new par_child();
$obj->callObj();
**//string 'Object value1' (length=13)**
par_child::callStatic();
**//string 'Static value2' (length=13)**
  • 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-06-10T20:26:34+00:00Added an answer on June 10, 2026 at 8:26 pm

    The parent:: is binded like the self:: keyword, always sees the context where it have been defined code wise, not from where it’s called, so in essence it works like the self:: keyword. If you need it to work like the $this use late static binding provieded static::. Consider this example:

    class A { 
        protected static $v = 'a';
        public static function staticsay() {
            print static::$v;
        }
    
    }
    class B extends A { 
        protected static $v = 'b';
        public static function say(){
            print parent::$v;
        }
    }
    class C extends B { 
        protected static $v = 'c';
        public static function selfsay(){
            print parent::$v;
        }
    } 
    
    C::say(); // prints 'a'
    C::selfsay(); // prints 'b'
    C::staticsay(); // prints 'c'
    

    Here we call the say() method on C it comes from the class B so it’s parent:: means A and the A::$v is ‘a’ so it prints that.

    While the parent:: in C points to the class B and it sees it’s $v as ‘b’.

    With php 5.3 comes late static binding and the static:: keyword that lets you access the static variables and methods in baseclasses static methods so the A::staticsay will see the $v from the class C.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a class called Object. The Object class has a member function
Imagine I have a method: void Method(bool parameter){ if(parameter){ // first case } else
System.out.println(1+2+3); System.out.println(1+2+3); output:- 33 123 First case is understood but the second case is
I have a base class pointer pointing to a derived class object. I am
First, a quote from the ole' manual on ArrayAccess::offsetSet() : This function is not
I am dynamically generating a function and assigning it to a class. This is
my Python class has some variables that require work to calculate the first time
Edit: I have added an answer on how to fix this in case someone
I have defined an S4 class called cell , instances of which I would
I have a text file like this: 11 2 3 4 11 111 Using

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.