note 69622 added to language.oop5.typehinting

From: Date: Wed, 13 Sep 2006 10:00:57 +0000
Subject: note 69622 added to language.oop5.typehinting
Groups: php.notes 
Request: Send a blank email to php-notes+get-117089@lists.php.net to get a copy of this message
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 ---- Server IP: 66.163.161.117 Probable Submitter: 218.17.96.1 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.typehinting.php Edit -- https://master.php.net/note/edit/69622 Del: integrated -- https://master.php.net/note/delete/69622/integrated Del: useless -- https://master.php.net/note/delete/69622/useless Del: bad code -- https://master.php.net/note/delete/69622/bad+code Del: spam -- https://master.php.net/note/delete/69622/spam Del: non-english -- https://master.php.net/note/delete/69622/non-english Del: in docs -- https://master.php.net/note/delete/69622/in+docs Del: other reasons-- https://master.php.net/note/delete/69622 Reject -- https://master.php.net/note/reject/69622 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117089) next »