note 55828 added to language.oop5.basic

From: Date: Sun, 14 Aug 2005 21:11:45 +0000
Subject: note 55828 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-93651@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55828 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55828&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55828&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55828&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55828&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55828&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55828&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55828&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93651) next »