A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearphp: Calling Static Classes through a variable - page 1
User InfoPosts
php: Calling Static Classes through a variable#1
Is there a way to call Static Classes / Methods by name?

Example:

$name = 'StaticClass';
($name)::foo();


I have classes which I keep all static methods in and I'd like to call them this way.

posted date: 2008-12-24 02:23:00


Re: php: Calling Static Classes through a variable#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-24 02:23:01


Re: php: Calling Static Classes through a variable#3
You can do something like this using the call_user_func functionit would look something like the following$name = 'staticClass';call_user_func(array($name, 'foo'));Hope this helps

posted date: 2008-12-24 02:37:00


Re: php: Calling Static Classes through a variable#4
Yeah, that's the kind of stuff I'm looking for. Though I hoped it would be easier.

posted date: 2008-12-24 02:38:00


Re: php: Calling Static Classes through a variable#5
$name::foo()is possible since PHP5.3. In earlier versions you have to use call_user_func(array($classname,$methodname))

posted date: 2008-12-24 02:39:00


Re: php: Calling Static Classes through a variable#6
what if we wanna pass value too...

posted date: 2010-05-17 17:21:00


Re: php: Calling Static Classes through a variable#7
@KoolKabin: pass arguments as further arguments to call_user_func. There's also call_user_func_array. See php.net.

posted date: 2010-05-24 12:26:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.