LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-08-2006, 08:57 AM   #1
joelhop
Member
 
Registered: Mar 2004
Location: Pennsylvania::USA
Distribution: Fedora Core 6
Posts: 100

Rep: Reputation: 15
Question Php Coding Question: Static Functions


Hello Everyone,

I've recently discovered the power of static functions but I am not sure that I am using them correctly. I am able to solve problems much more quickly with them, but I guess I have a question of placement when using static functions.

Say I've got a main page class called Page and within the class I have a static function:



static function getAnswer()
{
return Page::getNum();
}


This static function is calling another static function that is in the same class Page. Instead of saying Page:: is there anyway to say Self:: or something like that? Basically trying to say $this->::getNum() but that of course is not correct. I just don't want to hard code the class name, incase I want to pull these out later and build their own static-function build variables class or something. I would like each static function to be able to call other static functions in the same class.

Thanks
 
Old 08-09-2006, 05:45 AM   #2
debulu
Member
 
Registered: May 2006
Location: India
Distribution: Redhat
Posts: 49

Rep: Reputation: 15
I think you can use self::getNum() and I think it will work .I have tested it for static data members and hope it will work for member functions also.

Plz let me know whether it worked!!
 
Old 08-09-2006, 11:17 AM   #3
joelhop
Member
 
Registered: Mar 2004
Location: Pennsylvania::USA
Distribution: Fedora Core 6
Posts: 100

Original Poster
Rep: Reputation: 15
That works beautifully!

Example:

Class Statics
{

static function someFunction()
{
return do something
}

static function otherFunction()
{
return self::someFunction()
}

}

You can call other static functions of the same class by using self:: instead of the actual class name. (Statics:: in this case)

Thank You!

Last edited by joelhop; 08-09-2006 at 11:18 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Php Coding Question joelhop Programming 5 08-07-2006 02:09 PM
PHP Coding Question joelhop Programming 12 07-24-2006 05:52 PM
PHP Coding Question joelhop Programming 2 07-20-2006 06:16 PM
static functions in C++ abi_sh Programming 7 07-13-2005 04:09 PM
error coding Input/Output in functions in C shams Programming 2 08-27-2004 06:49 AM


All times are GMT -5. The time now is 05:23 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration