473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

static classes and methods

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
2 1219
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Thomas Matthews | last post by:
Hi, I have three classes: Category Author Publisher Each of these classes stores its information into a database table of <ID, text>. (They are fields that have a foreign key.) There is...
16
by: Bruno Rodrigues | last post by:
Hi In a class with simple methods like: Products.Insert(string name, string desc) Products.Update(int id, string name, string desc) Products.Delete(int id) What is better? Static or common...
3
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
17
by: Picho | last post by:
Hi all, I popped up this question a while ago, and I thought it was worth checking again now... (maybe something has changed or something will change). I read this book about component...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
6
by: MSDNAndi | last post by:
Hi, I have a baseclass (non-static) with some static and some non-static methods/fields/properties. In the baseclass in one of the static methods I need to do something like " somelogic...
4
by: DBC User | last post by:
I have a class with bunch of static methods. I could regourp all the static methods into seperate 3 or 4 classes. I was thinking about using Singlton pattern for all these 4 classes so that it...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
4
by: Steffen Bobek | last post by:
Extension methods are made for use with instances. I'd like to "misuse" them as static methods, too. Let me tell you my ambition: I use an extension method to serialize objects somehow like this:...
4
by: Rene | last post by:
Hi, I was wondering if anyone could tell me why extension methods must be declared on static classes. I mean, why not allowing them to be declared as static methods in regular instance classes?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.