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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:22:03+00:00 2026-05-26T12:22:03+00:00

I have simllar question like here: static-method-invocation , but in PHP. Simply, I want

  • 0

I have simllar question like here: static-method-invocation, but in PHP. Simply, I want have class like this:

static class ClassName{
   static public function methodName(){
         //blah blah blah
   }
}

and I want to call member method without name od class like this:

require_once(ClassName.php);

methodName();

Is it possible in PHP? Thanks for your answers!

  • 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-26T12:22:04+00:00Added an answer on May 26, 2026 at 12:22 pm

    You can not do what you’re looking for. The example call you give:

    methodName();
    

    Is calling a global function. Even static class functions are global as well, they always need the class-name to be called:

    ClassName::methodName();
    

    This calls the global static class function you’ve created in the include file.

    I can only guess what you’d like to achieve, maybe you can benefit from the feature that includes can return values:

    static class ClassName{
       static public function methodName(){
             //blah blah blah
       }
    }
    return 'ClassName';
    

    Including:

    $className = require_once(ClassName.php);
    $className::methodName();
    

    However this won’t work with reguire_once when the file has been loaded earlier.

    You can write a wrapper function to require_once files, store their return value into a global context array that keeps these values based on the file-name of the include.

    Keep in mind that the java language differs from PHP. The equivalent to the java static function would be the global function in PHP:

    function methodName(){
        //blah blah blah
    }
    

    Including:

    require_once(ClassName.php);
    methodName();
    

    That’s the PHP equivalent.

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

Sidebar

Related Questions

I have posted a question on here previously asking similar advise, but this project
Similar questions have been asked, but nothing exactly like mine, so here goes. We
I have a similar question to this one SQL products/productsales I want to do
Currently, I have URLs that look like this: http://www.example.com/user/create http://www.example.com/user/edit/1 But now, I have
I have a question similar to this but in the context of L2S. I
I have asked a similar question before here , but after much thought, and
For the record: I found a similar question here but I have to elaborate
I have a similar question here: Sphinx search ranking broken? , but thought I'd
I have a similar question than django cross-site reverse . But i think I
I have asked a similar question before, but I didn't have a firm grasp

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.