www.webdeveloper.com
Results 1 to 2 of 2

Thread: Calling Non-Static Method inside Static Method

  1. #1
    Join Date
    Sep 2006
    Posts
    655

    Question Calling Static Method inside non-Static Method

    Hi

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


    PHP Code:
    class Foo
    {
        static public function 
    Hello() {
            return 
    'Hello';
        }

        public function 
    World(){
            return 
    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??


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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    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. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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



Recent Articles