TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Classes isues (http://www.talkphp.com/advanced-php-programming/5056-classes-isues.html)

drago 10-23-2009 07:31 PM

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.

Tanax 10-23-2009 07:53 PM

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!" 


afraca 10-24-2009 05:01 AM

Quote:

Originally Posted by drago (Post 28954)
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 ;)

drago 10-24-2009 01:27 PM

Well thanks. I didnt expext to so rapid replies.
Its very explicite the example.


All times are GMT. The time now is 08:17 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0