Class Constructor Calls

When calling class constructors with no arguments, always include parentheses:
$foo = new MyClassName();
This is to maintain consistency with constructors that have arguments:
$foo = new MyClassName($arg1, $arg2);
Note :
If the class name is a variable, the variable will be evaluated first to get the class name, and then the
constructor will be called.
Use the same syntax:
$bar = ‘MyClassName’;
$foo = new $bar();
$foo = new $bar($arg1, $arg2);
Class Constructor CallsWhen calling class constructors with no arguments, always include parentheses:$foo = new MyClassName();
This is to maintain consistency with constructors that have arguments:$foo = new MyClassName($arg1, $arg2);
Note that if the class name is a variable, the variable will be evaluated first to get the class name, and then the
constructor will be called. Use the same syntax:$bar = ‘MyClassName’;$foo = new $bar();$foo = new $bar($arg1, $arg2);

Comments

Popular posts from this blog

How to call php functions inside smarty template directly

PHP / SQL Security – The Big Picture

Top 50 Web Hacking Techniques