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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:45:36+00:00 2026-06-09T02:45:36+00:00

I am a new in terms of PHP OOP programming, i don’t understand when

  • 0

I am a new in terms of PHP OOP programming, i don’t understand when and how the following class names are and when shall i use them :

$a = new Classname();
$a = new Classname;

$a = ClassName::function();
$a = ClassName::getInstance();

Many thanks and sorry for silly question:

  • 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-09T02:45:37+00:00Added an answer on June 9, 2026 at 2:45 am

    These are identical.

    $a = new Classname();
    $a = new Classname;
    

    You can use them interchangeably when the class constructor does not take, or does not require other parameters.

    Example:

    class Classname
    {
        public function __construct($var = null)
        {
            // ..
        }
    
        static public function getInstance()
        {
            // ..
        }
    }
    

    In this case you can use $a = new Classname; and $var will take the default value, or $a = new Classname('hello') and $var will be equal to the value passed.


    These are both static method calls.

    $a = ClassName::function();
    $a = ClassName::getInstance();
    

    One calls a method called “function” (which cannot exist – it is a reserved word), the other calls a method named “getInstance”. When you use them really depends on what the methods do.

    Static methods can be called without creating an object instance.

    I.e.

    Classname::staticMethod();
    

    versus

    $obj = new Classname;
    $obj->method;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to programming so excuse me if I get some terms wrong
I'm relatively new to web programming. New to Javascript, PHP, Ajax, etc. I have
I am fairly new to php so I am not sure of the names
http://codepad.viper-7.com/ezvlkQ So, I'm trying to figure out: ...?php $object = new A(); class A
I'm pretty new to using MVC3 so hopefully the terms I'm using are all
Could someone explain in layman terms what this actually does? XmlTextReader textReader = new
I'm getting a compiler error for this line: Collections.sort(terms, new QuerySorter_TFmaxIDF(myInteger)); My customized Comparator
Well, I encountered this new term in programming. What is it? How does it
I'm new to Django, moved from PHP with Propel ORM engine. So here is
[Disclaimer: I am new to PHP, and I am just learning, so please no

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.