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

  • Home
  • SEARCH
  • 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 7057225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:57:37+00:00 2026-05-28T03:57:37+00:00

Wondering how the example below is actually working, and how one would be able

  • 0

Wondering how the example below is actually working, and how one would be able to do something like dynamically. Using call_user_func or call_user_func_array doesn’t allow this to happen.

<?php
class Person
{
    public $name = "George";

    public function say_hi()
    {
            return ExtraMethods::hi();
    }
}

class ExtraMethods
{
    public function hi()
    {
            return "Hi, ".$this->name;
    }
}

$george = new Person();
echo $george->say_hi();
?>

this should result with:

Hi, George

Wondering why the instance method hi can be called not only statically (not surprised that this can happen in PHP), but why I am able to use $this

  • 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-28T03:57:38+00:00Added an answer on May 28, 2026 at 3:57 am

    From the manual:

    The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).

    So, according to the second portion, by design. Keep in mind it uses the actual object instance in existance though (in other words, if you add public $name = "SomethingElse"; to ExtraMethods, the result would still be Hi, George).

    Calling the method statically is not proper coding, but PHP forgives you, and issues only a Strict Error:

    "Strict Standards: Non-static method ExtraMethods::hi() should not be called statically, assuming $this from incompatible context in ..."
    

    Of course, in this instance, just passing the object as an argument would be far clearer and preferable.

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

Sidebar

Related Questions

I am wondering how I would go about externalizing a proc (example below) so
Wondering why the example below doesn't work? <a id=load_list href=#>Load the list</a> <ul></ul> <script
I was wondering if anyone had an example of what an array would look
I have JSON Object that looks something like the below object, this object can
I was wondering, whats the best practice on the example below. <?php if(isset($_POST['query'])){ $out
I was wondering why code block was used in this example below: possibly_hanging_job &
When implementing a class with multiple properties (like in the toy example below), what
I am wondering if there is a way to restrict what validates using one
I was just wondering when you have for example: var dir = new DirectoryInfo(@C:\Temp);
I was wondering if anyone can post an example of how to get 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.