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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:54:17+00:00 2026-06-05T01:54:17+00:00

I have 2 classes like class A { public function B () { return

  • 0

I have 2 classes like

class A {
     public function B () {
         return 'b';
     }
}

class C extends A {
     public function D () {
         return 'd';
     }
}

I know that to use function b in class C I do,

class A {
     public function B () {
         return 'b';
     }
}

class C extends A {
     public function D () {
         $b = parent::B();
         return 'd';
     }
}

But what about when I initiate the object? Do I have to do (which works)

$c = new C();
$b = $c -> b();

Or do I still have to use this parent keyword?

I tried doing,

$c = new C();
$b = $c -> parent::B();

But it does not work.

Thanks

  • 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-05T01:54:18+00:00Added an answer on June 5, 2026 at 1:54 am

    You do not need the parent keyword in the second example, since class C extends A, it inherits all of its member functions and variables. So, $c->b(); is perfectly valid. Here is a link to the documentation on the extends keyword, which states:

    Often you need classes with similar variables and functions to another
    existing class. In fact, it is good practice to define a generic class
    which can be used in all your projects and adapt this class for the
    needs of each of your specific projects. To facilitate this, classes
    can be extensions of other classes. The extended or derived class has
    all variables and functions of the base class
    (this is called
    ‘inheritance’ despite the fact that nobody died) and what you add in
    the extended definition.

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

Sidebar

Related Questions

I have a php classes like: class bar{ public $value; } class foo extends
I currently have service classes that look something like this public class UserService :
Assume you have several arbitrary classes like below: class Foo { $foovar; public function
I have two classes defined like public class PostleitzahlList : ObservableCollection<Postleitzahl> { } public
I have classes structured like this: Public MustInherit Class A ' several properties End
my code is like this: i have two classes first class: public class Box<E>
I have some classes extended this way: class Baseresidence extends CActiveRecord { public static
so i have a class which contains basic stuff like Class Test{ public function
I have two classes like this (simplified and renamed): class Base { public: virtual
If I have domain classes like: class A { short aCode //... static hasMany

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.