note 69622 deleted from language.oop5.typehinting by felipe

From: Date: Mon, 24 Mar 2008 23:22:48 +0000
Subject: note 69622 deleted from language.oop5.typehinting by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137531@lists.php.net to get a copy of this message
Note Submitter: ---- If one is type hinting for a specific class type but wishes for there to be a default option of no object at all (e.g., to work on the object if it exists, or do something else (e.g., print out data) if it doesn't exist), this can be done by (and only by) NULL: <?php function printBreadcrumbs(Smarty &$smarty = NULL) { $breadcrumbs = <add code here to make or obtain breadcrumbs>; if ($smarty != NULL) { $smarty->assign('breadcrumbs', $breadcrumbs); } else { print $breadcrumbs; } } ?> If one tries to change NULL to '' or the like, one will get this error message: Default value for parameters with a class type hint can only be NULL

« previous php.notes (#137531) next »