note 102139 added to language.references.return

From: Date: Fri, 28 Jan 2011 20:41:51 +0000
Subject: note 102139 added to language.references.return
Groups: php.notes 
Request: Send a blank email to php-notes+get-176482@lists.php.net to get a copy of this message
Sometimes, you would like to return NULL with a function returning reference, to indicate the end of chain of elements. However this generates E_NOTICE. Here is little tip, how to prevent that: <?php class Foo { const $nullGuard = NULL; // ... some declarations and definitions public function &next() { // ... if (!$end) return $bar; else return $this->nullGuard; } } ?> by doing this you can do smth like this without notices: <?php $f = new Foo(); // ... while (($item = $f->next()) != NULL) { // ... } ?> you may also use global variable: global $nullGuard; return $nullGuard; ---- Server IP: 69.147.83.197 Probable Submitter: 83.16.18.130 ---- Manual Page -- http://www.php.net/manual/en/language.references.return.php Edit -- https://master.php.net/note/edit/102139 Del: integrated -- https://master.php.net/note/delete/102139/integrated Del: useless -- https://master.php.net/note/delete/102139/useless Del: bad code -- https://master.php.net/note/delete/102139/bad+code Del: spam -- https://master.php.net/note/delete/102139/spam Del: non-english -- https://master.php.net/note/delete/102139/non-english Del: in docs -- https://master.php.net/note/delete/102139/in+docs Del: other reasons-- https://master.php.net/note/delete/102139 Reject -- https://master.php.net/note/reject/102139 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#176482) next »