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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:00:06+00:00 2026-05-12T05:00:06+00:00

I want to check is a function exists in a library that I am

  • 0

I want to check is a function exists in a library that I am creating, which is static. I’ve seen function and method_exists, but haven’t found a way that allows me to call them in a relative context. Here is a better example:

class myClass{
    function test1()
    {
        if(method_exists("myClass", "test1"))
        {
            echo "Hi";
        }
    }
    function test2()
    {
        if(method_exists($this, "test2"))
        {
            echo "Hi";
        }
    }
    function test3()
    {
        if(method_exists(self, "test3"))
        {
            echo "Hi";
        }
    }
}
// Echos Hi
myClass::test1();
// Trys to use 'self' as a string instead of a constant
myClass::test3();
// Echos Hi
$obj = new myClass;
$obj->test2();

I need to be able to make test 3 echo Hi if the function exists, without needing to take it out of static context. Given the keyword for accessing the class should be ‘self’, as $this is for assigned classes.

  • 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-12T05:00:06+00:00Added an answer on May 12, 2026 at 5:00 am

    static::class is available since PHP 5.5, and will return the "Late Static Binding" class name:

    class myClass {
        public static function test()
        {
            echo static::class.'::test()';
        }
    }
    
    class subClass extends myClass {}
    
    subClass::test() // should print "subClass::test()"
    

    get_called_class() does the same, and was introduced in PHP 5.3

    class myClass {
        public static function test()
        {
            echo get_called_class().'::test()';
        }
    }
    
    class subClass extends myClass {}
    
    subClass::test() // should print "subClass::test()"
    

    The get_class() function, which as of php 5.0.0 does not require any parameters if called within a class will return the name of the class in which the function was declared (e.g., the parent class):

    class myClass {
        public static function test()
        {
            echo get_class().'::test()';
        }
    }
    
    class subClass extends myClass {}
    
    subClass::test() // prints "myClass::test()"
    

    The __CLASS__ magic constant does the same [link].

    class myClass {
        public static function test()
        {
            echo __CLASS__.'::test()';
        }
    }
    
    class subClass extends myClass {}
    
    subClass::test() // prints "myClass::test()"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Faster DirectoryExists function? I want to check if some file exists on
I want to check for duplicated words right next to each other, but even
I want to check when the user double click on applictaion icon that no
Im looking for a way, in jQuery, to check if a UL exists AND
I want to check if a file exists on a remote webserver with php.
I want to check if a value exists in a sequence defined as <xsl:variable
I want to check the entered email id already exists in my database or
I'm not sure which php function to use for this.. How can I check
I have a form, I want to check the username is availability. I that
I want to check out all files in all subdirectories of a specified folder.

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.