note 55828 deleted from language.oop5.basic by bjori
| From: | bjori@php.net | Date: | Wed, 26 Apr 2006 16:48:47 +0000 |
| Subject: | note 55828 deleted from language.oop5.basic by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109771@lists.php.net to get a copy of this message | ||
Note Submitter:
----
on the post of tobias_demuth at web dot de at 04-May-2005 09:14 - this is completly useless what
you're doing:
<?php function __construct($foo = new bar)
{ } ?>
By usig "=" in the function-declaration you define a default-value for the case of the
variable is not passed to the function. Such values can only be static values, cause they will be
compiled before the execution of the script.
What you can do (in PHP 5) is: require which type of object (which class) the variable passed to the
fucntion should have:
<?php function __construct(bar $foo)
{ } ?>
If you want to construct an object automatically if it's not passed to thefunction you can do
the following
<?php function __construct(bar $foo = NULL)
{ if ($foo === NULL)
{ $foo = new bar(); } } ?>
please excuse my bad english.