Skip to content
Advertisement

Tag: class

PHP: Concatenate classes on each other

How can I concatenate a class onto another class in this manner? Keep in mind that I will always know everything in the class that needs to be concatenated ahead of time, so generalization is not an issue. Answer This will concatenate two objects together assuming they’re the same type

Array of objects within class in PHP

I recently realized my currently approach on a project would greatly improve with the use of better/more descriptive objects. As such, I realized that I want an array of objects to be a member of another class. Edit: I wasn’t clear as to what my question was. My question is thus: How do I have an array in class LogFile

Match a PHP class with a Regular Expression

I wanna catch Php classes from a file: and the result matches must be and Answer regexps are poor at parsing programming languages’ grammars. Consider tokenizer functions instead. e.g. http://php.net/manual/en/function.token-get-all.php see also this http://framework.zend.com/apidoc/core/Zend_Reflection/Zend_Reflection_File.html

Static class initializer in PHP

I have an helper class with some static functions. All the functions in the class require a ‘heavy’ initialization function to run once (as if it were a constructor). Is there a good practice for achieving this? The only thing I thought of was calling an init function, and breaking its flow if it has already run once (using a

Finding the PHP File (at run time) where a Class was Defined

Is there any reflection/introspection/magic in PHP that will let you find the PHP file where a particular class (or function) was defined? In other words, I have the name of a PHP class, or an instantiated object. I want to pass this to something (function, Reflection class, etc.) that would return the file system path where the class was defined.

What does new self(); mean in PHP?

I’ve never seen code like this: Is it the same as new className() ? EDIT If the class is inheritant,which class does it point to? Answer self points to the class in which it is written. So, if your getInstance method is in a class name MyClass, the following line : Will do the same as : Edit : a

PHP Fatal error: Using $this when not in object context

I’ve got a problem: I’m writing a new WebApp without a Framework. In my index.php I’m using: require_once(‘load.php’); And in load.php I’m using require_once(‘class.php’); to load my class.php. In my class.php I’ve got this error: Fatal error: Using $this when not in object context in class.php on line … (in this example it would be 11) An example how my

could static members use nonstatic members and vice versa?

could i use nonstatic members inside a static method? eg. and vice versa that is to say use static members inside non-static methods? Answer From http://php.net/manual/en/language.oop5.static.php Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. A property declared as static can not be accessed with an instantiated class object (though a static

How to get instance of a specific class in PHP?

I need to check if there exists an instance of class_A ,and if there does exist, get that instance. How to do it in PHP? As always, I think a simple example is best. Now my problem has become: How to store the instance in a static member variable of class_A when instantiating? It’ll be better if the instance can

Advertisement