Forum Moderators: coopster
I don't seem to be able to get onto the manual this morning so here's a quickie for any that know....
if I create a constructor for a class and call it like this:
$new = new myclass();
The constructor function is executed right?
But, if I call it like this:
$new = new myclass;
Will I get an instance of the object without executing the constructor?
Many thanks
Nick
I was just looking for a neat way to invoke an instance for two differnent situations. One where the constructor was needed (although it could just be a regular method) and one where it was not.
No bit deal to just make a method and call when needed, but, it seemed logical at the time....
Nick
public class Aaron {
public Aaron(String s, int a) {
System.out.println('two parameter');
}
public Aaron(String s) {
System.out.println('one parameter');
}
} Aaron a = new Aaron('Carter', 15); would print two parameter while Aaron a = new Aaron('Carter'); would print one parameter. However, this is not possible in PHP.
class Aaron {
function Aaron($str1, $str2) {
echo "two paras:";
}
function Aaron($str1) {
echo "one para:";
}
}This will always print "one para" no matter whether you create the instance using two parameters or just one. The second declaration of Aaron will override the first one. Andreas