473,407 Members | 2,546 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,407 software developers and data experts.

Syntax for calling a static method on a "variable" class?

Hi,

I have a classname in a variable, and I whish to call a static method on
that class, what's the syntax for that?

I'm using PHP5.

Eg.

<?php
class Foo {
public static function bar() {
echo "Foo bar";
}
}

$class_name = 'Foo';

$foo = new $class_name(); // I can do this.

$class_name::bar() // This is an error... "parse error, unexpected
T_PAAMAYIM_NEKUDOTAYIM"

Foo::bar() // This is how it's normally done..
?>

So what I want to do is $class_name::bar(), is it possible and what is the
syntax?

Regards,

Peter Albertsson
Jul 17 '05 #1
2 1736
"Peter Albertsson" <Pe***********************@antispOm.comhem.se> wrote in
message news:N0*********************@newsc.telia.net...
Hi,

I have a classname in a variable, and I whish to call a static method on
that class, what's the syntax for that?


http://www.php.net/call_user_func/
Jul 17 '05 #2
Great! Thanks!

// Peter

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:la********************@comcast.com...
"Peter Albertsson" <Pe***********************@antispOm.comhem.se> wrote in
message news:N0*********************@newsc.telia.net...
Hi,

I have a classname in a variable, and I whish to call a static method on
that class, what's the syntax for that?


http://www.php.net/call_user_func/

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marcin Vorbrodt | last post by:
So I have a class Math that looks like this: Math { public: static Real PI(void); }; Real Math::PI(void) { return 4.0 * atan(1.0); }
4
by: santosh | last post by:
Hello, I have a doubt about static variable. class B { private: static int x; public: static set(int y) {
0
by: Bryan Green | last post by:
So I'm working on a project for a C# class I'm taking, where I need to keep some running totals via static variables. I need three classes for three different types of objects. The base class and...
7
by: Action | last post by:
in c++ if i put static int count = 0; in a method; count can only accessed inside the method and retain it's value. is there equilvant thing in C#? thx
3
by: XPhaktor | last post by:
In C#, how do I replace using VB local static variable declarations to handle method reentrancy. Note, if you use a class-scope variable instead of a local one, then you run the risk of...
5
by: John Kelsey | last post by:
Back in the "old" C/C++ days, I used to declare static variables inside functions. Something like... // just a silly example to demonstrate the technique int foo(void) { static int NextVal =...
6
by: depalau | last post by:
I'm running into some issues on maintaining a static variable across the lifetime of a web service and I was wondering if anyone could help. Background: We have developed a C#/1.1 web service...
9
by: LamSoft | last post by:
Class B { public B() {} } Class A : B { public static string ABC = "myABC"; public A() {} }
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
8
Motoma
by: Motoma | last post by:
Good evening everyone. I am starting to re-explore C++, and I wanted to build a singleton class. Unfortunately, when I set things up as I do in PHP, it doesn't work out for me. I hope that the...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.