Results 1 to 2 of 2

Thread: Calling Non-Static Method inside Static Method

  1. #1
    Join Date
    Sep 2006

    Question Calling Static Method inside non-Static Method


    I would like to know if the following is correct way of doing?

    PHP Code:
    class Foo
        static public function 
    Hello() {

        public function 
    self::Hello() .' World';

    Here I am calling a static method inside a non-static method. It works for sure, but just wanted to confirm if its correct way??

    Last edited by phantom007; 06-03-2014 at 03:06 AM.

  2. #2
    Join Date
    Aug 2004
    Looks okay to we -- with the exceptions that in this trivial example, there is no apparent reason why the static method should be static, or even be a method at all (it could just be a class property).

    On a side note, I almost never use static anything. About the only exception is the (very rare) case when I make a singleton class, in which case the method that returns the object needs to be static. (And I can go for months or years without creating a singleton. )
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center