By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,334 Members | 2,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,334 IT Pros & Developers. It's quick & easy.

static classes and methods

P: n/a
I may have more of a design problem, but here goes.
I have a class that has 3 methods. One method simply calls the other
two. I wanted to make the class static, and to do this in php, you
just have to make the function static. So I did that for all three
functions. But now I cannot call the other two functions from the
first function.

What do I need to do to make the one function in the class call the
other 2. The only way I know right now, is to not make any of the
functions static.
Jan 3 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, 03 Jan 2008 18:03:36 +0100, Anthony Smith <mr******@hotmail.com>
wrote:
I may have more of a design problem, but here goes.
I have a class that has 3 methods. One method simply calls the other
two. I wanted to make the class static, and to do this in php, you
just have to make the function static. So I did that for all three
functions. But now I cannot call the other two functions from the
first function.
self::functionname();

<?php
class foo{
static function bar(){
self::foz();
self::baz();
}
static function foz(){echo 'hello';}
static function baz(){echo ', world';}
}
foo::bar();
?>
--
Rik Wasmus
Jan 3 '08 #2

P: n/a
On Jan 3, 11:17 am, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Thu, 03 Jan 2008 18:03:36 +0100, Anthony Smith <mrsmi...@hotmail.com>
wrote:
I may have more of a design problem, but here goes.
I have a class that has 3 methods. One method simply calls the other
two. I wanted to make the class static, and to do this in php, you
just have to make the function static. So I did that for all three
functions. But now I cannot call the other two functions from the
first function.

self::functionname();

<?php
class foo{
static function bar(){
self::foz();
self::baz();
}
static function foz(){echo 'hello';}
static function baz(){echo ', world';}}

foo::bar();
?>
--
Rik Wasmus
Thanks you very much Rik. I have a follow up. Let say in my class, I
would like to include a properties file:
require_once 'website.inc'; // has a value called $var_from_file in
it.

I would like to use a value from this file.
static function foz(){echo $var_from_file;}

How would I do that?
Jan 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.