TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-23-2009, 07:31 PM   #1 (permalink)
The Visitor
 
Join Date: Oct 2009
Posts: 4
Thanks: 0
drago is on a distinguished road
Default Classes isues

Hello to everybody. Im not a guru in php, so i want to ask if is possible to use function and variables from a class without creating an object of that class.

To be more explicite. I have a general class that contain a lot of functions that do things that are not related. I just want to use them.
drago is offline  
Reply With Quote
Old 10-23-2009, 07:53 PM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yes, use static functions in the class.

PHP Code:
class Myclass
{

    private static 
$classvariable;

    public static function 
Myfunc($param)
    {

          
self::$classvariable $param;
          return 
self::$classvariable;

    }

}

$var Myclass::Myfunc("This is actually working!");

echo 
$var// echoes "This is actually working!" 
__________________
Tanax is offline  
Reply With Quote
Old 10-24-2009, 05:01 AM   #3 (permalink)
The Wanderer
 
Join Date: Sep 2009
Posts: 9
Thanks: 1
afraca is on a distinguished road
Default

Quote:
Originally Posted by drago View Post
To be more explicite. I have a general class that contain a lot of functions that do things that are not related. I just want to use them.
But be aware that working with classes, and in particular, object orientated programming can be sooooo much more of a use than just be a collection of functions. Try googling for "php5 oop tutorial" or something ;)
afraca is offline  
Reply With Quote
Old 10-24-2009, 01:27 PM   #4 (permalink)
The Visitor
 
Join Date: Oct 2009
Posts: 4
Thanks: 0
drago is on a distinguished road
Default

Well thanks. I didnt expext to so rapid replies.
Its very explicite the example.
drago is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Abstract Classes sketchMedia Advanced PHP Programming 18 02-28-2013 05:38 AM
abstract classes and constructors captainmerton Absolute Beginners 9 06-08-2009 06:36 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
Sibling Classes not getting along trs21219 Advanced PHP Programming 3 04-27-2008 03:57 AM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM


All times are GMT. The time now is 11:36 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design