note 82116 added to functions.returning-values

From: Date: Fri, 28 Mar 2008 02:27:13 +0000
Subject: note 82116 added to functions.returning-values
Groups: php.notes 
Request: Send a blank email to php-notes+get-137650@lists.php.net to get a copy of this message
Be careful about using "do this thing or die()" logic in your return lines. It doesn't work as you'd expect: <?php function myfunc1() { return('thingy' or die('otherthingy')); } function myfunc2() { return 'thingy' or die('otherthingy'); } function myfunc3() { return('thingy') or die('otherthingy'); } function myfunc4() { return 'thingy' or 'otherthingy'; } function myfunc5() { $x = 'thingy' or 'otherthingy'; return $x; } echo myfunc1(). "\n". myfunc2(). "\n". myfunc3(). "\n". myfunc4(). "\n". myfunc5(). "\n"; ?> Only myfunc5() returns 'thingy' - the rest return 1. ---- Server IP: 208.69.120.35 Probable Submitter: 76.244.184.105 ---- Manual Page -- http://www.php.net/manual/en/functions.returning-values.php Edit -- https://master.php.net/note/edit/82116 Del: integrated -- https://master.php.net/note/delete/82116/integrated Del: useless -- https://master.php.net/note/delete/82116/useless Del: bad code -- https://master.php.net/note/delete/82116/bad+code Del: spam -- https://master.php.net/note/delete/82116/spam Del: non-english -- https://master.php.net/note/delete/82116/non-english Del: in docs -- https://master.php.net/note/delete/82116/in+docs Del: other reasons-- https://master.php.net/note/delete/82116 Reject -- https://master.php.net/note/reject/82116 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137650) next »