PHP Fatal error: Cannot redeclare class

You have a class of the same name declared more than once. Maybe via multiple includes. When including other files you need to use something like include_once “something.php”; to prevent multiple inclusions. It’s very easy for this to happen, though not always obvious, since you could have a long chain of files being included by … Read more

What is the difference between “Class.forName()” and “Class.forName().newInstance()”?

Maybe an example demonstrating how both methods are used will help you to understand things better. So, consider the following class: package test; public class Demo { public Demo() { System.out.println(“Hi!”); } public static void main(String[] args) throws Exception { Class clazz = Class.forName(“test.Demo”); Demo demo = (Demo) clazz.newInstance(); } } As explained in its … Read more

How to loop through all the properties of a class?

Use Reflection: Type type = obj.GetType(); PropertyInfo[] properties = type.GetProperties(); foreach (PropertyInfo property in properties) { Console.WriteLine(“Name: ” + property.Name + “, Value: ” + property.GetValue(obj, null)); } for Excel – what tools/reference item must be added to gain access to BindingFlags, as there is no “System.Reflection” entry in the list Edit: You can also … Read more

List all base classes in a hierarchy of given class?

inspect.getmro(cls) works for both new and old style classes and returns the same as NewClass.mro(): a list of the class and all its ancestor classes, in the order used for method resolution. >>> class A(object): >>> pass >>> >>> class B(A): >>> pass >>> >>> import inspect >>> inspect.getmro(B) (<class ‘__main__.B’>, <class ‘__main__.A’>, <type ‘object’>)

How to avoid having class data shared among instances?

You want this: class a: def __init__(self): self.list = [] Declaring the variables inside the class declaration makes them “class” members and not instance members. Declaring them inside the __init__ method makes sure that a new instance of the members is created alongside every new instance of the object, which is the behavior you’re looking … Read more

UML class diagram enum

They are simply showed like this: _______________________ | <<enumeration>> | | DaysOfTheWeek | |_____________________| | Sunday | | Monday | | Tuesday | | … | |_____________________| And then just have an association between that and your class.