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 Office 2007, Excel has a maximum of 65,000 rows. Office 2007 bumped that
Certain methods in Java will block until they can do something, like ServerSocket.accept() and
I am introducing automated integration testing to a mature application that until now has
I asked a similar question yesterday that was specific to a technology, but now
Yesterday, I posted an answer to a question that included several (unknown to me
Up until recently, I've been storing multiple values into different hashes with the same
Up until now I have been using std::string in my C++ applications for embedded
I didn't upgrade to Vista until May or so and one of the things
The code below continues many lines until it ends with a expected /veotherwise /vechoose.
I'm a ClearCase newbie and up until now have been used to SVN. Therefore,

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.