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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:01:10+00:00 2026-05-13T08:01:10+00:00

Up until the yesterday I though that both of these methods for accessing a

  • 0

Up until the yesterday I though that both of these methods for accessing a class where identical. Google turned up noting (either that or my keywords were bad). What is the difference between accessing a class by defining a new instance of the class rather than just calling the class methods directly.

I hardly understood what I just ask, since I have not a clue what I’m asking but allow me to give a few examples to help out.

For as long as I have been using classes in PHP I have been defining a instance of the class then accessing the methods from that variable. Here is an example:

<?php
class Myclass
{
   public function my_method() {
      return "This is my method"; 
   }
}
$myclass = new Myclass();

echo $myclass->my_method(); // output: This is my method
?>

What is the difference between that and doing this?

<?php
class Myclass
{
   public function my_method() {
      return "This is my method";
   }
}

echo Myclass::my_method(); // output: This is my method
?>

I hope I was clear enough. If not a brief synopsis would be – What is the difference between creating a new instance of a class then calling a method of the class with “$class->mymethod();,” or just directly calling the method like so: “Myclass::mymethod();”?

Thanks in advance.

  • 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-13T08:01:11+00:00Added an answer on May 13, 2026 at 8:01 am

    First, you should understand the difference between a class and an object, or a class and an instance of a class.

    For example, where class is “Circle”, an instance might be “this particular circle”. Class Circle might have members $center and $radius – every point has these. But the values of these are different for every point.

    $class->mymethod() is a call to an instance method, for instance $circle->Length(). You are saying something to a particular instance of an object. This method will have access to class members – variables that belong to the instance. In PHP you gain access to these instance variables using keyword $this.

    For instance $circle->Length() might be implemented as return 2*Pi*$this->radius;

    What happens when you say Circle::Length()? Nothing. This is syntax for calling static methods. Because you did not say which circle. Circle as a class does not have length.

    Static method is declared with keyword static. Whatever it does it has no access to any instances of the class. It’s something that a class as a whole does.

    For instance, if you want to calculate length of the circle without actually creating one, then there might be static function calculateLength($radius) in the class circle. And you would call it as Circle::calculateLength($myRadius)

    In my opinion you should not even think about static methods until you understand the non-static ones.

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

Sidebar

Related Questions

Until yesterday I thought that it was not possible to send background SMS without
I used facebook share button without xfbml until yesterday. Yesterday I see that share
Until yesterday everything was normal but today i try to lauch my application using
Until yesterday everything was fine to my localhost, but starting yesterday, localhost is not
Up until yesterday (June 20, 2012) my application was running smoothly. As of yesterday,
Up until yesterday I had a perfectly working app on my iPhone. I made
I'm sure my app worked right until yesterday, when I got this error: Failed
I just started using virtualenv, and it was working normally until yesterday. Now, and
Yesterday, I posted an answer to a question that included several (unknown to me
i have a Magento site in which the checkout process worked fine until yesterday

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.