How can I call member variables of a class within a static method?

I am using some method to autoload helper files with functions. The only problem I am having now, is how to call the variables in that class.

Because I am not instantiating it as an object, $this won't work. But what will?

class some_helperclass { var $some_variable = '007'; public static function some_func() { //return 'all ok'; if (self::some_variable !== FALSE) { return self::ip_adres; } }

I can call the function from anywhere now with the help of spl_autoload_register().

some_helperclass:: some_func();

-------------Problems Reply------------

You have to use self::$some_variable. Put the $ in there.

http://www.php.net/manual/en/language.oop5.static.php

The member variable has to be declared static too.

Declare the variable as static too.

private static $some_variable;

Category:php Views:0 Time:2009-11-17

Related post

  • Can I access static member variables defined on the subclass from a method on the abstract superclass? 2010-08-18

    I have an abstract class with a single concrete method. In this method I want to use a static class variable from the classes that derive from the one the method is declared in. To do so, I of course have to declare this static variable in the abstra

  • Updating reference to a member variable in use 2008-09-22

    I got this síngleton cache object and it exposes an IEnumerable property which just returns a private IEnumerable variable. I have a static method on my singleton object that updates this member variable (that exists on the single 'Instance' instance

  • best approach to member variables in object-oriented javascript? 2009-01-12

    This is a follow up to a question I just posted. I'm wondering how you all handle member variables in javascript clases when using MyClass.prototype to define methods. If you define all of the methods in the constructor function: function MyClass(){

  • C# coding standards for private member variables 2009-04-13

    I saw two common approaches for coding standards for private member variables: class Foo { private int _i; private string _id; } and class Foo { private int m_i; private string m_id; } I believe the latter is coming from C++. Also, many people specif

  • Unit testing functions that only change private member variables? 2009-08-14

    I am currently writing unit tests for a ViewModel in my project that uses Prism and the MVVM pattern. My view mainly consists of an ItemsControl that reacts to different mouse events (LeftMouseButtonDown, LeftMouseButtonUp etc.). When such a mouse ev

  • Declare Member Variables with gen-class in Clojure 2009-10-18

    I'm learning how to extend Java classes in Clojure, but I don't see a way declare new member variables; I only see a way for methods. (ns test.aclass (:gen-class :methods [[foo [] String]])) Is there a :members keyword or another way of declaring mem

  • Class member variables, methods and their state 2010-05-27

    How should class member variables be used in combination with class methods? Let's say I have a class 'C' with a member variable 'someData'. I call C.getData(), which does not return a value but instead puts data in C.someData. The class that instant

  • Shall I make every function static, which do not touch the member variable? 2011-05-26

    What is the Design and Performance impact for making all functions static which do not touch the member variable of the class? --------------Solutions------------- You should actually consider making them non-static free functions, as explained in de

  • Using Public Final Member Variables and Overridable Methods in a Constructor 2011-08-14

    I have questions about a couple techniques I'm using in designing a class. I've declared some of its members as public final instead of private, and the constructor calls overridable methods. I know that these are normally considered bad practice, bu

  • Java static methods accessing private variables 2011-02-26

    I was under the impression that private non-static variables could only be accessed by methods called on the object that the variables reside in, but this is not the case. Could someone please explain the reasoning behind why the following compiles a

  • When is this VB6 member variable destroyed? 2008-09-17

    Suppose I have a class module clsMyClass with an object as a member variable. Listed below are two complete implementations of this very simple class. Implementation 1: Dim oObj As New clsObject Implementation 2: Dim oObj As clsObject Private Sub Cla

  • What kind of prefix do you use for member variables? 2008-09-21

    No doubt, it's essential for understanding code to give member variables a prefix so that they can easily be distinguished from "normal" variables. But what kind of prefix do you use? I have been working on projects where we used m_ as prefix, on oth

  • If you are using getters and setters, how should you name the private member variables? 2008-10-03

    As kind of a follow up to this question about prefixes, I agree with most people on the thread that prefixes are bad. But what about if you are using getters and setters? Then you need to differeniate the publicly accessible getter name from the priv

  • What is the member variables list after the colon in a constructor good for? 2008-10-16

    I'm reading this C++ open source code and I came to a constructor but I don't get it ( basically because I don't know C++ :P ) I understand C and Java very well. TransparentObject::TransparentObject( int w, int x, int y, int z ) : _someMethod( 0 ), _

  • C++ performance of accessing member variables versus local variables 2008-10-26

    Is it more efficient for a class to access member variables or local variables? For example, suppose you have a (callback) method whose sole responsibility is to receive data, perform calculations on it, then pass it off to other classes. Performance

  • Retrieve an object that has a member variable with the longest string length 2008-10-30

    Given a Generic List of objects that contain a member variable that is a string, what is the best way to get the object that contains the string with the longest length? ie. assuming val1 is the string I'm comparing: 0 : { val1 = "a" } 1 : { val1 = "

  • Why does this const member function allow a member variable to be modified? 2008-11-16

    class String { private: char* rep; public: String (const char*); void toUpper() const; }; String :: String (const char* s) { rep = new char [strlen(s)+1]; strcpy (rep, s); } void String :: toUpper () const { for (int i = 0; rep [i]; i++) rep[i] = tou

  • C# member variable initialization; best practice? 2008-11-18

    Is it better to initialize class member variables on declaration private List<Thing> _things = new List<Thing>(); private int _arb = 99; or in the default constructor? private List<Thing> _things; private int _arb; public TheClass()

  • Overriding a member variable in C++ 2008-11-18

    I have run into a bit of a tricky problem in some C++ code, which is most easily described using code. I have classes that are something like: class MyVarBase { } class MyVar : public MyVarBase { int Foo(); } class MyBase { public: MyBase(MyVarBase*

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.093 (s). 11 q(s)