class

When to use a Class vs. Function in PHP

The lightbulb has yet to go on for this... I'd really love an easy to understand explanation of the advantage to using a class in php over just using functions. Here's a simple example of the thought I'm having now and am wondering if a class is more efficient: Say I have a mini calendar widget that I've built in php. I'm thinking ...

C++ type traits to check if class has operator/member

hi Is it possible to use boost type traits or some other mechanism to check if a particular template parameter has an operator/function, e.g. std::vector as a template parameter has operator[], while std::pair does not. ...

Called child´s constant not available in static funcion in parent

I have a static function in a class that needs to be called from several child classes. I need a constant from the calling child class to be available in that function. To have these constants available in other places, the child classes have a function that returns the value of that constant (php 5.2.9). However, when in the parent cla...

How can I access the contents of this PHP array?

Below are the files in PHP that I am trying to include a file that holds an array into my class and then access the array. if I run print_r() on it I get results but if I try to access the array item individually I get nothing, can anyone help me please? <?php // config.class.php /* example usages $config = Config::getInstance(PATH_TO_...

C# change labels created in public class from form button click

Having hard time understanding classes and why I can't access certain object. How can i modify the code so I can change "map"(which is a bunch of labels) properties in all of my classes/events? The method Draw2d() creates a couple of labels on the main form that I wish to change on different events(button click in this example). Can so...

create a FlashBuilder4 mxml class instance using ActionScript?

I have a number of GUI dialogs defined using MXML. Assuming these mxml objects have been compiled into my application, is there any way to instantiate these objects using ActionScript, sort of like this? myFoo: Mxml2ActionScriptClass("FOO.mxml") = new AutomagicalMXMLFactory( "FOO.mxml"); myFoo.addEventListener(etc etc) th...

c++: Dynamically choose which subclass to create

Hello, I am new to c++ and i have a question. Lets say we have a base class Base and two derived classes, Derived1 and Derived2. f.e. Derived1 has a constructor taking a integer and Derived2 a constructor taking a boolean. Is it possible to determine at run time (or at compile time) which of those two subclasses to create and assign i...

Some questions about the performance of PHP Objects

Right now since I am new to using Objects in PHP I feel like in my head, I think of a PHP object as being something big and bulky. This makes me want to use them less often, I feel Like I am taking really simple code and really over-complicating it by putting it into objects. If I have a database, cache, session, core, and user objec...

java: how can i set a class's field by a field name that stored in a variable

Hi. how can i set a field in a class that it's name is dynamic and stored in a string variable ? public class test { public String a1; public string a2; public test(String key) { this.key='found'; <--- error } } ...

search&replace array key using PHP and CakePHP Set Class

hi, i need to write function that searches & replaces key in multi-dimensional array in following manner: input array: [0] => Array ( [Foo] => sometext [Foo2] => Array ( [lorem] => 1 [Avatar2] => Array ( [meta_key] => avatar2 [...

Add Classes to first level list tags

Hi, is there a way to add class to only one level on li tags? in m case at the moment it looks like this: <ul> <li></li> <li> <ul> <li></li> <li></li> </ul> </li> <li></li> </ul> And this is what I need <ul> <li class="lev-one"></li> <li class="lev-one"> <ul> ...

foreach in class: I cannot return all the ele in arr.

Hello, Well, I keep improving my form generation classes and stuck in returning all the country elements in country_data array. Only first two elements is displaying on dropdown options. Here is dropdown class: //drop down form class class DropDown { function __construct ($form, $field_label, $field_name, $field_desc, $dropdown_da...

Class Inheritance in Javascript

Hi Everyone, I am wondering how to simulate Class Inheritance in JavaScript. I know class doesn't apply to JavaScript, the way we use is Functions to create objects and do the inheritance things through Prototype object. For example, how do you convert this structure into JavaScript : public class Mankind { public string name; ...

What are the factors to consider when choosing between interfaces and abstract classes?

When designing my software, I began with interfaces since this seems to be the "standard". Then I switched to abstract classes because they seem better suited to the problem at hand. However I'm not sure if I've missed out on some considerations when making this design choice. Other than domain specific issues which I have thought abo...

does not name a type error in C++

Hi, I have two classes declared as below: class User { public: MyMessageBox dataMsgBox; }; class MyMessageBox { public: void sendMessage(Message *msg, User *recvr); Message receiveMessage(); vector<Message> *dataMessageList; }; When I try to compile it using gcc, it gives the following error: 'MyMessageBox does not name a type'....

I have managed to compile java-program but I cannot execute it.

I have just installed JDK on Windows Vista. After that I set proper values for the 4 environment variables: classpath, include, lib, path. After that I was able to compile my HelloWorld-program (I got a *.class file). But when I try to execute the compiled program (I type java HelloWorldApp) it does not work. The Java write a lot of stuf...

jQuery return position of list element with class on table column click

I was wondering how to return the position of a list element with a class of 'currentTab' in the following unordered list: <ul id="coverTabs"> <li class="currentTab"><a href="#">Individual</a></li> <li><a href="#">Couple</a></li> <li><a href="#">Family</a></li> <li><a href="#">Single parent family</a></li> </ul> The ...

Can I require class-functions only if the class is instantiated in php?

Trying to improve my code's agility and loading time, I thought of doing this, so that the functions would be required only if the class was instantiated. class User { public function __construct() { require('all_user_fns.php'); } } Inside all_user_fns.php will reside all User class's functions. Is that feasible (...

Best performance for loading settings in PHP?

My latest idea for do settings across my php project I am building was to store all my settings in a config PHP file, the php file will just return an array like this... <?php /** * @Filename app-config.php * @description Array to return to our config class */ return array( 'db_host' => 'localhost', 'db_name' => 'socialnetwor...

What Considerations need to create a DB Helper Class in .Net?

What Considerations do we need when creating a DB helper class in .Net? ...