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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:48:04+00:00 2026-06-13T02:48:04+00:00

This is the working code, but i want to know without using another object(commented

  • 0

This is the working code, but i want to know without using another object(commented $foo) how could i use printItem() method of class Foo using the $bar object. New to oop programming concept so may be a weak thing to ask but really unable to locate 🙁

I use scope resolution operator to use printItem() of Foo class, now my query is when we can use this functionality then what is the use of creating objects ? When to use scope resolution operators in proper coding environment.

<?php

class Foo
{
    public function printItem($string)
    {
        echo "This is in class Foo ". $string ."<br />";
    }

    public function printPHP()
    {
        echo "PHP is great "."<br />";
    }
}

class Bar extends Foo
{
    public function printItem($string)
    {
        echo "This is in class Bar ". $string ."<br />";
    }
}       

//$foo = new Foo;
$bar = new Bar;

$bar->printPHP();
$bar->printItem("Bar class object");
//Foo::printItem("Mental Case");
  • 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-13T02:48:05+00:00Added an answer on June 13, 2026 at 2:48 am

    define printItem as static method and you can use Foo::printItem("Mental Case");
    or call it in child method:

    public function printItem($string)
    {
        parent::printItem($string);
        echo "This is in class Bar ". $string ."<br />";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code and its working but i want it to return dailyTotals
Got this line of code here but its not working. private void Button_Click(object sender,
I have this working code, but now i need to be able to change
I am working on this code but even after consulting other threads I am
this seems to be weird but it really happened. I have this code working
This code is working on other test environment but not on mine. Do you
This code was working earlier today, then randomly stopped, something must of changed, but
runat=server /> But this code is not working How can I add multiple controls
<a href=details.php?phoneid=1><img src=phone01.jpg></a> When I write the code like this it's working fine. But
i have tried this code to redirect a php page.but it s not working

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.